checkBoxList

Discussion in 'ASP .Net' started by Guest, Nov 27, 2004.

  1. Guest

    Guest Guest

    hi all

    i have checkboxlist box control
    i need to get the count of slected index
    thanks
     
    Guest, Nov 27, 2004
    #1
    1. Advertisements

  2. Hi Sara,

    You want to use IndexOf as you loop through the items.

    CheckBoxList1.Items.IndexOf (itm)

    See the full code sample below.

    Let us know if this helps?

    Ken
    Microsoft MVP [ASP.NET]


    Private Sub Button1_Click _
    (ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles Button1.Click
    Dim itm As ListItem
    For Each itm In CheckBoxList1.Items
    If itm.Selected = True Then
    itm.Attributes.Add("class", "itmclass")
    Response.Write(CheckBoxList1.Items.IndexOf _
    (itm).ToString & "<br>")
    End If
    Next
    End Sub

    <asp:CheckBoxList id="CheckBoxList1" runat="server">
    <asp:ListItem Value="Red">Red</asp:ListItem>
    <asp:ListItem Value="Blue">Blue</asp:ListItem>
    <asp:ListItem Value="Green">Green</asp:ListItem>
    </asp:CheckBoxList>

    <P>&nbsp;</P>
    <P>
    <asp:Button id="Button1" runat="server" Text="Button"></asp:Button></P>
     
    Ken Cox [Microsoft MVP], Nov 28, 2004
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.