<div style="margin-top: 8px; margin-right: 8px; margin-bottom: 8px; margin-left: 8px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); " mce_style="color:
#000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; margin-top: 8px; margin-right: 8px; margin-bottom: 8px; margin-left: 8px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip:
initial; background-color: #ffffff; ">
(The following is a complete re-edit of the original post which was rambling, confusing etc...)
I have a form with a dynamically generated checklist:
<asp:CheckBoxList ID="cblGames" runat="server" DataSourceID="sqlGames" DataTextField="Game" DataValueField="Id" </asp:CheckBoxList>
<asp:SqlDataSource ID="sqlGames" runat="server" ConnectionString="<%$ ConnectionStrings:Games %>"
SelectCommand="SELECT [Id], [Game], [ShowWaitingList] FROM [Aanbod] WHERE ([ShowWaitingList] = @ShowWaitingList)">
<SelectParameters><asp:Parameter DefaultValue="true" Name="ShowWaitingList" Type="Boolean" /></SelectParameters>
The following code-behind is supposed to check those boxes that correspond to values stored in a database. It fails and I don't know why. Any ideas?
regards, Guy (p.s. [AanbodId] and [Id] are equivalent.)
if (!Page.IsPostBack && Request.QueryString["id"] != null)
// Code that gets the data goes here. Removed for brevity's sake //
ListItem currentCheckBox = cblGames.Items.FindByValue(reader["AanbodId"].ToString());
if (currentCheckBox != null)
currentCheckBox.Selected = true;
First of all, here's a tip using the Insert Code tool: Once you've inserted a code block, don't edit it. That's probably how you ended up with all those spurious <SPAN> tags in your C#. (No disrespect intended - just something I had to learn the hard
Secondly, .aspx pages by default post back to themselves, so you shouln't need to redirect a page back to itself. If you use Response.Redirect to do that, you'll loose all the information saved in viewstate, which may or may not explain why you're having
HI, (this post can be ignored, see re-edit above)
I tried to edit the code down because it's a little convoluted (I'm a newbie) and I hoped just presenting the key would make it easier to understand the problem. I'm sure those span tags didn't show in the preview!
Anyway, the page only redirects after a new record is inserted. This insures that the user is presented with a blank form to enter the next record. I see the usefulness of viewstate for many tasks, but think it less than useful for database inserts which
most of the time involve moving onto the next record. I considered resetting all entry fields to blanks in the code behind, but a redirect is simpler (if not exactly elegant).
So I am still stuck with the original problem. Is it clear what I want to be done and what the problem is?
Both scenarios/solutions I've tried take place with viewstate (not that it is used). Neither give me the result I want.
Are you running the above code in the CheckBoxList.DataBound handler or where? (It won't work before that event.)
(And you're right about preview mode; it's useless. You just have to learn the hard way, like all of us, that the code block starts and ends with the two blank lines above and below the code, and that once you click Insert, the only safe way to edit it
is in HTML mode. And even in HTML mode, you can't put HTML tags between the <PRE> and </PRE> tags.)