Link to home
Start Free TrialLog in
Avatar of Erwin Pombett
Erwin PombettFlag for Switzerland

asked on

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

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?
Avatar of BalkisBr
BalkisBr

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

Avatar of Erwin Pombett

ASKER

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...

 
foreach
 
(
GridViewRow
 row 
in
 GridView1
.
Rows
)

Open in new window

thanks for further help.
i'm not using a gridview but a datagrid,

' Iterating through Rows of a DataGrid
    For Each GridItem As DataGridItem In MyDataGrid.Items
        ' ....
    Next
 
' 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
    Next
 
    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                    

           


ASKER CERTIFIED SOLUTION
Avatar of BalkisBr
BalkisBr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial