I have a aspx page which contains the following CheckBoxList.
<form id="form1" runat="server">
<asp:CheckBoxList id="check1" AutoPostBack="True" TextAlign="Right" OnSelectedIndexChanged="Check" runat="server">
</asp:CheckBoxList>
<br />
<asp:label id="mess" runat="server"/>
</form>
Then in the .vb page I have a query in the Page_Load sub where I get all the customer names and whether or not they are a validated user (either true or false). When I loop through the dataset I want to add a ListItem for each name and if they are a validated user I want to have the checkbox checked. Here is my loop for the dataset
For i = 0 To dt.Rows.Count - 1
If CStr(dt.Rows(i).Item("isValid")) = True Then
"<asp:ListItem>" + CStr(dt.Rows(i).Item("Name")) + "</asp:ListItem>"
Else
"<asp:ListItem>" + CStr(dt.Rows(i).Item("Name")) + "</asp:ListItem>"
End If
I know the above loop isnt going to add the listItems, how do I add the checked ListItems in my loop? Any help would be appreciated. Thanks
I know there is a way to check if a box is checked such as doing
check1.Items(i).Selected
How do you check if it is not checked? Something like this?:
check1.Items(i).Selected = False
You can add items to the
CheckBoxListby usingCheckBoxList.Items.Add(ListItem).ListItemhas a propertySelectedfor the checked state: