Loop through checkboxes in listview control

Posted on 2008-11-04
Last Modified: 2013-12-17
I binding listview control with checkbox and populate from database like this.......

 <asp:ListView ID="List" runat="server" DataKeyNames="Id">
                            <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
                                <asp:CheckBox ID="ListCheckBoxField" runat="server" Text='<%#Eval("Description") %>' OnCheckedChanged="ListCheckBoxField_CheckedChanged" />

Now in code-behind how can I loop through all checked checkboxes and if checked then get id of checkbox ??
Question by:mugsey
    LVL 4

    Expert Comment

    Going by your code, all of your checkboxes will have the same ID.
    You will need to set the name to something unique maybe based on the data.
    LVL 13

    Accepted Solution

    try something like this

    foreach (ListViewItem item in myListView.Items)
     CheckBox i = (CheckBox)item.FindControl("ListCheckBoxField");


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    6 Experts available now in Live!

    Get 1:1 Help Now