高分求解答!!!
1
protected void Button1_Click(object sender, EventArgs e)
2
{
3
string selectedKeys = ""; //保存所有选中的记录的主键
4
for (int i = 0; i < GVDealNow.Rows.Count; i++)
5
{
6
GridViewRow row = GVDealNow.Rows[i];
7
if (row.RowType == DataControlRowType.DataRow)
8
{
9
//检查是否选中,假设CheckBox的ID为Checkbox1,且在GVDealNow的第一列中
10
CheckBox cb = (CheckBox)row.Cells[9].FindControl("CBsig");
11
//如果选中,则记录选中记录的主键
12
if (cb.Checked)
13
{
14
selectedKeys = selectedKeys + GVDealNow.DataKeys[row.RowIndex].Value.ToString() + ",";
15
}
16
}
17
}
18
if (selectedKeys != "")
19
{
20
selectedKeys = selectedKeys.TrimEnd(new char[] { ',' });
21
//生成sql语句,并执行删除
22
string sql = "delete from tb_Card where CardID in (" + selectedKeys + ")";
23
SqlConnection conn = new SqlConnection("连接字符串");
24
SqlCommand cmd = new SqlCommand(sql);
25
cmd.Connection = conn;
26
cmd.CommandType = CommandType.Text;
27
conn.Open();
28
cmd.ExecuteNonQuery();
29
conn.Close();
30
}
31
else
32
{
33
Response.Write("未选中要删除的记录!");
34
}
35![]()
36![]()
37
38
39
40
}
第一列 和第十列 是模板列!
protected void Button1_Click(object sender, EventArgs e)2
{3
string selectedKeys = ""; //保存所有选中的记录的主键4
for (int i = 0; i < GVDealNow.Rows.Count; i++)5
{6
GridViewRow row = GVDealNow.Rows[i];7
if (row.RowType == DataControlRowType.DataRow)8
{9
//检查是否选中,假设CheckBox的ID为Checkbox1,且在GVDealNow的第一列中10
CheckBox cb = (CheckBox)row.Cells[9].FindControl("CBsig");11
//如果选中,则记录选中记录的主键12
if (cb.Checked)13
{14
selectedKeys = selectedKeys + GVDealNow.DataKeys[row.RowIndex].Value.ToString() + ",";15
}16
}17
}18
if (selectedKeys != "")19
{20
selectedKeys = selectedKeys.TrimEnd(new char[] { ',' });21
//生成sql语句,并执行删除22
string sql = "delete from tb_Card where CardID in (" + selectedKeys + ")";23
SqlConnection conn = new SqlConnection("连接字符串");24
SqlCommand cmd = new SqlCommand(sql);25
cmd.Connection = conn;26
cmd.CommandType = CommandType.Text;27
conn.Open();28
cmd.ExecuteNonQuery();29
conn.Close();30
}31
else32
{33
Response.Write("未选中要删除的记录!");34
}35

36

37
38
39
40
}
绑定代码如下
string sqlstr = "select * from tb_Card C where C.CardStatus=0";
this.GVDealNow.DataKeyNames = new string[] { "CardID" };
sqlBind.gvBind(GVDealNow, sqlstr);请大家帮忙解决下!!

这是数据库字段!~!


浙公网安备 33010602011771号