Click here to Skip to main content
15,847,077 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have taken a check box in a grid view column.I want access all the values of the grid view row whose corresponding check box is checked.

Share this answer
Follow below code.It explains the action required by you on button click:

protected void Button1_Click(object sender, EventArgs e)
   SqlConnection conn = new SqlConnection();
   conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["yourstring name"].ConnectionString;
   DataTable dtable = new DataTable();
   dtable.Columns.Add(new DataColumn("field name", typeof(string)));
   //Define datatable based on your requirement
   Session["dt"] = dtable;
   foreach (GridViewRow gvrow in yourgridview.Rows)
    CheckBox chk = (CheckBox)gvrow.Cells[3].FindControl("yourcheckbox");//checkbox is in  4th column,hence Cells[3]               
      if (chk != null && chk.Checked)
            DataRow dd = dtable.NewRow();
            dd["field name"] = (gvrow.Cells[1].Text);//store data appropriately            
            GridView1.DataSource = dtable;//getting data in another gridview
            Session["dt"] = dtable;
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