简体   繁体   English

如何将数组列表值绑定到 VB.NET 中的复选框中

[英]How to bind an array list values into check boxes in VB.NET

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.我的代码隐藏文件中有一个大约 100 个名称的数组列表,我希望将这些名称显示为复选框以供最终用户选择。 How can i display them on my ASPX.Page.我怎样才能在我的 ASPX.Page 上显示它们。

Please give me suggestions.请给我建议。 Thanks in advance!提前致谢!

Use a CheckBoxList control and bind the array to it.使用 CheckBoxList 控件并将数组绑定到它。

Add a CheckBoxList control to the .aspx file.将 CheckBoxList 控件添加到 .aspx 文件。

In the code-behind class for the page, bind the array to the CheckBoxList control.在页面的代码隐藏类中,将数组绑定到 CheckBoxList 控件。

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.这是做一个相互排斥的radiolist的唯一方法,因为分组有问题。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM