gridview中checkbox多选的问题
stringsqlText="(";for(inti=0;i<GridView1.Rows.Count;i++){CheckBoxcbox=(CheckBox)GridV...
string sqlText = "(";
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if (cbox.Checked)
// 我设断点测试,进不了这里,cbox.Checked==true 也进不了,写成cbox.Checked=true就是全选
{
sqlText = sqlText + Convert.ToInt32(GridView1.DataKeys[i].Value) + ",";
}
}
sqlText = sqlText.Substring(0, sqlText.Length - 1) + ")";
sqlText = "select * from bookinfo where 图书编号 in "+ sqlText ;
try
{
con.Open();
OracleCommand cmd = new OracleCommand(sqlText, con);
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
//若有错误发生,输出错误信息
Response.Write(ex.Message);
} 展开
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if (cbox.Checked)
// 我设断点测试,进不了这里,cbox.Checked==true 也进不了,写成cbox.Checked=true就是全选
{
sqlText = sqlText + Convert.ToInt32(GridView1.DataKeys[i].Value) + ",";
}
}
sqlText = sqlText.Substring(0, sqlText.Length - 1) + ")";
sqlText = "select * from bookinfo where 图书编号 in "+ sqlText ;
try
{
con.Open();
OracleCommand cmd = new OracleCommand(sqlText, con);
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
//若有错误发生,输出错误信息
Response.Write(ex.Message);
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询