Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get the values form multiple check box selection

Status
Not open for further replies.

taree

Technical User
May 31, 2008
316
US
How can I get the values of a multiple check box selection and store it in variable. I try this and does not work can someone help me. thanks

Code:
 <form id="form1" runat="server">
    <div style="text-align: left">
        Select Review Participants<br />
        <br />
        <asp:CheckBoxList ID="cblReview" runat="server" Height="80px" Width="352px">
        </asp:CheckBoxList>
       
        <asp:Button ID="btnReviewer" runat="server" Text="Button" Width="144px" /></div>
    </form>

 Protected Sub btnReviewer_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReviewer.Click
        Dim I As Integer
        Dim valStr As String = ""

        For I = 0 To cblReview.Items.Count - 1
            Dim chkSelect As CheckBox = CType(FindControl("cblReview"), CheckBox)
            If chkSelect.checked> 0 Then
                valStr = valStr & ","
            End If
        Next
        


    End Sub
 
Code:
var ids = new List<string>();
foreach(var item in cblReview.Items)
{
   if(!item.Checked) continue;
   ids.Add(item.Value);
}
//do something with ids

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Thank you Jason for your help. I am getting "item " is not declared error?
 
Thank you guys for your help and time.

Here is how I did it and work for me.

Code:
   Dim strReviewrsId As String = ""
        For Each li As ListItem In cblReview.Items
            If li.Selected Then
                strReviewrsId = strReviewrsId & li.Value & ","
            End If
        Next
        strReviewrsId = Left(strReviewrsId, Len(strReviewrsId) - 1)
        Response.Write(strReviewrsId)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top