datagrid with checkbox, how to check values after click on a button?

Posted on 2009-04-17
Last Modified: 2013-12-17
hello experts,

how can i recover the checked  values from a datagrid containing checkboxes,
the datagrid is bind to arraylist of objetcs.

my button is not in datagrid,
how can i recover the values when button is clicked?
Question by:toshi_
    LVL 3

    Expert Comment

    You can simply make a loop in your datagrid rows and use findControl to locate your checkbox.
                foreach (GridViewRow row in GridView1.Rows)
                    CheckBox check = (CheckBox)row.FindControl("myControlName");
                    if (check.Checked)

    Open in new window


    Author Comment

    hello BalkisBr,

    thank you for your help,

    my problem is that i can not pass Rows in Datagrid, in the following row,
    do i have to transtype it? if yes how , i'^ve tried to datagrid...


    Open in new window

    thanks for further help.

    Author Comment

    i'm not using a gridview but a datagrid,


    Author Comment

    ' Iterating through Rows of a DataGrid
        For Each GridItem As DataGridItem In MyDataGrid.Items
            ' ....
    ' 1. Getting the Value from a Bound Column in DataGrid
        ' Get name from Cell(0)
        Dim Name As String = GridItem.Cells(0).Text
    ' 2. Getting the Value of a TextBox Control in DataGrid
        ' Get text from textbox in Cell(1)
        Dim Age As String = CType(GridItem.FindControl("AgeField"), TextBox).Text
    ' 3. Getting the Value from CheckBox Control in DataGrid
        ' Get Checked property of Checkbox control
        Dim IsGraduate As Boolean = CType(GridItem.FindControl("IsGraduateField"), CheckBox).Checked
    ' 4. Getting the Value from CheckBoxList Web Control in DataGrid
        ' Get Values From CheckBoxList
        Dim Skills As String = String.Empty
        Dim CheckList As CheckBoxList = CType(GridItem.FindControl("CheckBoxList1"), CheckBoxList)
        For Each Item As ListItem In CheckList.Items
            If (Item.Selected) Then
                Skills = Skills & Item.Value & ","
            End If
        Skills = Skills.TrimEnd(",")
    ' 5. Getting the Value from a RadioButtonList Web Control in a DataGrid
        ' Get RadioButtonList Selected text
        Dim Experience As String = CType(GridItem.FindControl("RadioButtonList1"), RadioButtonList).SelectedValue
    ' 6. Getting the Value from a DropDownList Web Control in a DataGrid
        ' Get DropDownList Selected text
        Dim Degree As String = CType(GridItem.FindControl("DropDownList1"), DropDownList).SelectedValue                    


    LVL 3

    Accepted Solution

    Sorry, Lunch time...
    I was about to aswer that you only need to replace my code with "Items".

    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.

    Join & Write a Comment

    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    745 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

    15 Experts available now in Live!

    Get 1:1 Help Now