I have an array list of around 100 names in my code behind file and i'm looking to display these names as check boxes to select by the end user. How can i display them on my ASPX.Page.
Please give me suggestions. Thanks in advance!
Use a CheckBoxList control and bind the array to it.
Add a CheckBoxList control to the .aspx file.
In the code-behind class for the page, bind the array to the CheckBoxList control.
For more details check this link : Displaying an Array as a Group of Checkboxes
Another option would be to use a repeater, then bind to the repeater. This is the only way to do a mutually exclusive radiolist, since the grouping is buggy. something like:
<asp:repeater runat="server" id="rptList">
<itemTemplate>
<asp:checkbox runat="server" id="ckBox" text='<%# eval("nameoftextfield")%>' value='<%# eval("nameofvaluefield")%>' />
</itemTemplate>
</asp:repeater>
then in the code, you can evaluate like this:
Public Sub RetrieveValues()
Dim ckBox As CheckBox
Dim name As String
Dim value As String
For Each item As RepeaterItem In Me.rptList.Items
If item.ItemType = ListItemType.Item Or item.ItemType = ListItemType.AlternatingItem Then
ckBox = CType(item.FindControl("ckBox"), CheckBox)
If ckBox.Checked = True Then
name = ckBox.Text
value = ckBox.Attributes("value")
End If
End If
Next
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.