Trying to prepopulate checkbox list control
Posted on 2009-04-28
I have the following checkboxlist control:
<asp:CheckBoxList ID="chbxlstType" CssClass="lbltextblcksmbld" RepeatDirection="horizontal" runat="server">
<asp:ListItem Text="AE" Value="0"></asp:ListItem>
<asp:ListItem Text="C" Value="0"></asp:ListItem>
<asp:ListItem Text="NPQ" Value="0"></asp:ListItem>
The user will go in and check various check boxes and submit their selections to the databases. In the insert to the db we are building a string of values and inserting them into 1 varchar field. Like so:
foreach (ListItem liType in chbxlstType.Items)
strTypelist += liType.Value + ",";
So for example, if all 3 listitems were checked and then submitted the value in the db ends up being (0,0,0). Or if for example only the first and third listitems were selected the value in the db would be (0,,0).
So now when the user comes back to the form and i need the listitems to be prepopulated with the selections the user made previously. So i need to do sometype of a comparison against the db value and check the appropriate boxes accordingly. Any suggestions as to the best way to do it in C#?