Click here to Skip to main content
15,923,789 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.
Posted

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

C#
protected void Button1_Click(object sender, EventArgs e)
{          
   SqlConnection conn = new SqlConnection();
   conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["yourstring name"].ConnectionString;
   conn.Open();
   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)
      {
            dtable=(DataTable)Session["dt"];
            DataRow dd = dtable.NewRow();
            dd["field name"] = (gvrow.Cells[1].Text);//store data appropriately            
            dtable.Rows.Add(dd);
            GridView1.DataSource = dtable;//getting data in another gridview
            GridView1.DataBind();                        
            Session["dt"] = dtable;
     }
  }
}
 
Share this answer
 
v5

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