• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 410
  • Last Modified:

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?
0
toshi_
Asked:
toshi_
  • 3
  • 2
1 Solution
 
BalkisBrCommented:
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

0
 
toshi_Author Commented:
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.
0
 
toshi_Author Commented:
i'm not using a gridview but a datagrid,

0
 
toshi_Author Commented:
' 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                    

           


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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now