All Checked Row in GriView not inserting into Database.
I have tried inserting checked row in a GridView but only one row is submitted each try i click on submit button. I want all checked row submitted.
My Code
protected void ImageButton3_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in gvDetails.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
string id1 = row.Cells[1].Text;
string id2 = row.Cells[2].Text;
string id3 = row.Cells[5].Text;
string id5 = row.Cells[6].Text;
string id6 = row.Cells[8].Text;
//Finiding checkbox control in gridview for particular row
CheckBox chkdelete = (CheckBox)row.FindControl("chkSelect");
//Condition to check checkbox selected or not
if (chkdelete.Checked)
{
string insertSQL22 = "INSERT INTO stocktracking (";
insertSQL22 += "stockid,packinglist,datesent,datereceived,location,status)";
insertSQL22 += "VALUES('";
insertSQL22 += id1 + "','";
insertSQL22 += id2 + "','";
insertSQL22 += id3 + "','";
insertSQL22 += id5 + "','";
insertSQL22 += id6 + "','";
insertSQL22 += 1 + "')";
String connectionString22 = "Data Source=NERE\\SQLEXPRESS01; Initial Catalog= kaging;Integrated Security=True";
SqlConnection con22 = new SqlConnection(connectionString22);
SqlCommand cmd22 = new SqlCommand(insertSQL22, con22);
int added22 = 0;
try
{
con22.Open();
Response.Write(insertSQL22);
added22 = cmd22.ExecuteNonQuery();
if (added22 == 1)
{
Response.Redirect("Default20.aspx");
}
else
{
}
}
catch (Exception err)
{
Response.Write(err.ToString());
}
finally
{
con22.Close();
}
}
}
}
BindUserDetails();
}
Please help fix code