我有一个表t1和表t2。我的gridview填充了t1的值。如果选中复选框,则在每行的t1复选框t1将整行插入t2表并保存数据。 我希望我插入的行数据保存在t2中并与t1一起使用,然后检查比较行的复选框。 任何hwlp将不胜感激:
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
GridViewRow row = GridView1.Rows[i];
CheckBox Chbox = (CheckBox)row.FindControl("chb1");
if (Chbox.Checked == true)
{
select++;
}
}
if (select == 0)
{
}
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
string id = GridView1.Rows[i].Cells[1].Text;
string name = GridView1.Rows[i].Cells[2].Text;
string City = GridView1.Rows[i].Cells[3].Text;
string Age = GridView1.Rows[i].Cells[4].Text;
GridViewRow row = GridView1.Rows[i];
CheckBox Chbox = (CheckBox)row.FindControl("chb1");
if (Chbox.Checked == true)
{
con.Open();
com = new SqlCommand("insert into info2 values('" + id + "','" + name + "','" + City + "','" + Age + "')", con);
com.ExecuteNonQuery();
con.Close();
foreach (GridViewRow grow in GridView1.Rows)
{
int id1 = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
con.Open();
com = new SqlCommand("Select * FROM info where id='" + id1 + "'", con);
SqlDataReader dr = com.ExecuteReader();
CheckBox ChkBoxRows = (CheckBox)row.FindControl("chbl1");
if (dr.Read())
{
Response.Write(GridView1.Rows[i].Cells[2].ToString());
}
//if (dr = 1)
//{
// Chbox.Checked = true;
//}
//else
//{
// Chbox.Checked = true;
//}
//com.ExecuteNonQuery();
con.Close();