Loop through asp:checkboxlist (VB.net) : CheckBoxList « Asp Control « ASP.Net






Loop through asp:checkboxlist (VB.net)

<%@ Page Language=VB Debug=true %>
<script runat=server>
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
    Dim MyItem as ListItem
    lblMessage.Text = ""
    For Each MyItem in cbl1.Items
        If MyItem.Selected = True Then
            lblMessage.Text = lblMessage.Text _
                & MyItem.Text & "<BR>"
        End If
    Next
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Creating a Basic CheckBoxList Control</TITLE>
</HEAD>
<form runat="server">
<BR><BR>
<asp:Label
    id="lblMessage"
    runat="server"
/>
<BR><BR>
<asp:checkboxlist 
    id="cbl1" 
    runat="server"
    cellpadding="5"
    cellspacing="5"
    repeatcolumns="3"
    repeatdirection="Horizontal"
    repeatlayout="Table"
    textalign="Right"
>
    <asp:ListItem value="12">Blue</asp:ListItem>
    <asp:ListItem value="11">Red</asp:ListItem>
    <asp:ListItem value="2">Green</asp:ListItem>
    <asp:ListItem value="32">Purple</asp:ListItem>
    <asp:ListItem value="8">Black</asp:ListItem>
    <asp:ListItem value="15" Selected>Gold</asp:ListItem>
</asp:checkboxlist>
<BR><BR>
<asp:button 
    id="butOK"
    text="OK"
    type="Submit"
    onclick="SubmitBtn_Click" 
    runat="server"
/>
</form>
</BODY>
</HTML>
           
       








Related examples in the same category

1.Set asp:CheckBoxList Repeat Direction (VB.net)
2.Get selected value from asp:checkboxlist (VB.net)
3.Define and use asp checkboxlist in code behind (C#)
4.Get selected item from asp:checkboxlist (C#)