日期:2014-05-18 浏览次数:20902 次
protected void allDelDropDownList() { string rowsID = ""; for (int i = 0; i < gV_ArticleCotrol.Rows.Count; i++) { CheckBox chbox = (CheckBox)gV_ArticleCotrol.Rows[i].FindControl("checkBoxX"); if (chbox.Checked == true) { rowsID = rowsID + gV_ArticleCotrol.DataKeys[i].Value.ToString();//获取选中ID string delStr = "delete from articleControl_Table where artid='" + rowsID + "' "; SqlConnection sqlDel = connectSqlData(); sqlDel.Open(); SqlCommand delCommand = new SqlCommand(delStr, sqlDel); delCommand.ExecuteNonQuery(); sqlDel.Close(); gV_ArticleCotrol.EditIndex = -1; gV_ArticleCotrol.DataSource = SqlDataArtSouce; gV_ArticleCotrol.DataBind(); } } gv_DataBind(); }
string rowsID = "";
------解决方案--------------------
rowsID = rowsID + gV_ArticleCotrol.DataKeys[i].Value.ToString();//获取选中ID
为啥要不断的加呢。。。
------解决方案--------------------
rowsID = rowsID + gV_ArticleCotrol.DataKeys[i].Value.ToString();//获取选中ID
rowsID怎么会循环递加呢??
rowsID = gV_ArticleCotrol.DataKeys[i].Value.ToString();//获取选中ID
------解决方案--------------------
string rowsID = "";
for (int i = 0; i < gV_ArticleCotrol.Rows.Count; i++)
{
CheckBox chbox = (CheckBox)gV_ArticleCotrol.Rows[i].FindControl("checkBoxX");
if (chbox.Checked == true)
{
rowsID = rowsID +","+ gV_ArticleCotrol.DataKeys[i].Value.ToString();//获取选中ID
}
}
string delStr = "delete from articleControl_Table where artid in('" + rowsID + "' )";
SqlConnection sqlDel = connectSqlData();
sqlDel.Open();
SqlCommand delCommand = new SqlCommand(delStr, sqlDel);
delCommand.ExecuteNonQuery();
sqlDel.Close();
gV_ArticleCotrol.EditIndex = -1;
gV_ArticleCotrol.DataSource = SqlDataArtSouce;
gV_ArticleCotrol.DataBind();