Although your code have may concerns, I am writing the snippet which should solve your problem.
Replace this for Button2_Click-
protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TDB"].ConnectionString);
for (int i = 0; i < GridView1.Rows.Count - 1; i++)
{
GridViewRow row = GridView1.Rows[i];
CheckBox cb = (CheckBox)row.FindControl("CheckBox1");
if (cb.Checked == true)
{
select++;
}
}
for (int i = 0; i < GridView1.Rows.Count-1; i++)
{
GridViewRow row = GridView1.Rows[i];
string U_Id = ((TextBox)GridView1.Rows[i].FindControl("TextBox5")).Text;
string Name = ((TextBox)GridView1.Rows[i].FindControl("TextBox1")).Text;
string Email_Id = ((TextBox)GridView1.Rows[i].FindControl("TextBox2")).Text;
CheckBox cb = (CheckBox)Rows[i].FindControl("CheckBox1");
if (cb.Checked == true)
{
InsertData(U_Id, Name, Email_Id, System.DateTime.Now.ToString());
Response.Write("Record inserted successfully");
}
}
}
In case this doesn't resolve your problem, please let me know :)