Click here to Skip to main content
15,912,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,


how can i fetch the values of checked check boxes in the grid view on a button click event
Posted
Updated 24-Jul-12 19:13pm
v2

Here is a good article, which covers your issue

Selecting multiple checkboxes inside a GridView control[^]

another one[^]

Regards
Sebastian
 
Share this answer
 
v2
Comments
Pradeep_kaushik 25-Jul-12 1:57am    
its working but i want to fetch the whole row and want to insert those values in a new table


this example working for only cell
C#
Label1.Text = ((CheckBox)GridView1.SelectedRow.Cells[1].Controls[0]).Checked.ToString();

or
try
C#
protected void CheckBox_Checked(object sender, EventArgs e)
{
     CheckBox chkbox = (CheckBox)sender;
     GridViewRow r = (GridViewRow)chkbox.NamingContainer;
    if(chkbox.Checked)
      {
             //You can update values by referring (r.FindControl("id of sth control") as SomeTypeControl).PublicProperty
      }
}
 
Share this answer
 
v4
you can fetch values as
C#
foreach(Gridviewrow gvr in Gridview1.Rows)
{
 if(((CheckBox)gvr.FindControl("CheckBox1")).Checked == true)
 {

   int CustomerId = int.parse(gvr.Cells[2].Text);
 }
}
 
Share this answer
 
you can used like
SQL
foreach (GridViewRow gvr in showDetails.Rows)
                       {
                           CheckBox chkSelect = gvr.FindControl("chkSelect") as CheckBox;

                           if (chkSelect != null && chkSelect.Checked == true)
                           {
                               if (gvr.Cells[1].Text != "Email Not Valid")
                               {
                                   blObj.importingUserIntoGroup(gvr.Cells[1].Text, user_Id);
                               }
                           }

                       }
 
Share this answer
 
Hi,

Try this:
C#
foreach(GridViewRow gvr in GridView1.Rows)
{
    // You should have the checkbox in the item template
    if(((CheckBox)gvr.FindControl("CheckBox1")).Checked)
    {
        // Your code goes here.
        // Access yout controls using gvr.FindControl() in case of item templates
        // Use "gvr.Cells[index].Text" in case of grid bound column
    }
}


All the best.



--Amit
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900