62,046
社区成员
发帖
与我相关
我的任务
分享
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
string xjg=this.TextBox1.Text;
string whereClause = string.Empty;
CheckBox chk;
foreach (GridViewRow r in GridView1.Rows)
{
chk = (CheckBox)r.FindControl("CheckBox1");
if (chk != null)
{
if (chk.Checked)
{
if (whereClause == string.Empty)
whereClause += "'" + GridView1.DataKeys[r.RowIndex].Value.ToString() + "'";
else
whereClause += ",'" + GridView1.DataKeys[r.RowIndex].Value.ToString() + "'";
}
}
}
if (whereClause != string.Empty)
{
SqlConnection cn = new SqlConnection(@"server=.\SQLExpress;uid=sa;pwd=sa;database=pubs");
//假设你的gjid为数字类型字段
string strSQL = ""Update sc_gj set fy='" + xjg + "' where gjid in (" + whereClause + ")";
SqlCommand cmd = new SqlCommand(strSQL, cn);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
}
//下面重新绑定GridView
BindGrid();
}
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if (cbox.Checked == true)
{
strSql = "Update sc_gj set fy='" + xjg + "' where gjid=" + dtTable.Rows[i]["gjid"].ToString() + "";
shuju.ExcuteSql(strSql);
}
}