Is anybody tell me how to iterate <asp:Checkbox> array loop.

liunx

Guest
Dear Friend,

Is anybody tell me how to iterate <asp:Checkbox> array loop.

e.g. in PHP

<INPUT TYPE="CHECKBOX" NAME="CHK[]">

I am using foreach loop.


Will you pl guide me for below ASP.Net with C# code.

While (daDetail.Read())
{
lblLabel.Text += "<input type='checkbox' name='chk[" + daDetail["Module_id"] + i.ToString() + "]' value='A'>Add
}


This will create multiple checkbox. Now I want to know that how to get value of selected checkbox ?


Thanking You,From what I can see, I'm guessing that you are trying to create a checkbox list and then get the selected value on postback. I'll create a VB example of how you might do this (note: I'm creating this on the fly so it might not work and syntax may even be incorrect, however you should be able to figure out the context of the code) Good Luck!:

<html>
<head>
<script runat="server">

Private Sub Page_Load(byval sender as object, byval e as eventargs)
If Not Page.IsPostback Then
While daDetail.Read
Dim listItem as New ListItem
listItem.Text = daDetail("Module_id")
listItem.Value = daDetail("Module_id")
cblTest.Items.Add(listItem)
End While
Else
For Each listItem As ListItem In cblTest.Items
If listItem.Selected = True Then
If lblSelectedItem.Text <> "" Then lblSelectedItem.Text &= ", "
lblSelectedItem.Text &= listItem.Text
End If
Next
End If

End Sub
</script>
</head>
<body>
<form runat="server">
<asp:checkboxlist id="cblTest" runat="server"></asp:checkboxlist>
<br />
<asp:label id="lblSelectedItem" runat="Server"></asp:label>
</form>
</body>
</html>
 
Back
Top