How to include check box array and access them in vb.net

admin

Administrator
Staff member
Hello everybody,

I need to include checkbox arra in vb.net as visual basic.

I had declared them as below.

<TD><input id="chkPriv[]" type="checkbox" value="1" runat="server"></TD>
<TD><input id="chkPriv[]" type="checkbox" value="2" runat="server"></TD>
<TD><input id="chkPriv[]" type="checkbox" value="3" runat="server"></TD>
<TD><input id="chkPriv[]" type="checkbox" value="4" runat="server"></TD>
<TD><input id="chkPriv[]" type="checkbox" value="4" runat="server"></TD>

But i am not able to access the below values

1. chkPriv.length
2. chkPriv[1].value

I don't know any other way to include and access them.

It is urgent and kindly suggest.

Regards,
Siva R

mail: <!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e --> the stuff in the html does not have any numbers behind it.... so when the form gets sent to the server a [1] value is not sent... all of those checkboxes to the server have the same name. Try putting 1, 2, 3 in the markup and so on. You might need to avoid a formal array and rig this thing.There is a Web Control in .Net called CheckBoxList. You can use it as an array of CheckBoxes.

In your HTML code you add this control using the following code:

<asp:CheckBoxList id="CheckBoxList1" runat="server"></asp:CheckBoxList>

The nice thing about it is that you can easily populate this array with data from a database.

If you want to populate it during design time, you can do this:
<asp:CheckBoxList id="CheckBoxList1" runat="server">
<asp:ListItem Value="Hello">Item1</asp:ListItem>
<asp:ListItem Value="Hello">Item2</asp:ListItem>
<asp:ListItem Value="Hello">Item3</asp:ListItem>
</asp:CheckBoxList>

The value of each individual CheckBox in this control you can access in the fashion:

CheckBoxList1.Items.Item(index).Value

where index is like an index of an array.

Good Luck!
 
Back
Top