Try the below coding(edit this as per your project)
protected void Button1_Click1(object sender, EventArgs e)
{
string a = Request.QueryString["var"];
foreach (GridViewRow gvr in GridView1.Rows)
{
if (gvr.RowType == DataControlRowType.DataRow)
{
CheckBox cb = (CheckBox)(gvr.FindControl("CheckBox1"));
if (cb.Checked == true)
{ SqlConnection cn = new SqlConnection("Data Source=FABSYSXX-PC; Initial Catalog=rule; User Id=sa; Pwd=saadmin");
cn.Open();
SqlCommand cmd = new SqlCommand("Insert into Trans values('" + Session["count"].ToString() + "','" + gvr.Cells[1].Text + "','" + gvr.Cells[2].Text + "','" + gvr.Cells[3].Text + "','" + a + "')", cn);
int iCount = cmd.ExecuteNonQuery();
cn.Close();
}
}
}
Response.Write("<SCRIPT>alert('Transcation completed Successfully!!!! ')</SCRIPT>");