日期:2014-05-17  浏览次数:20551 次

GridView中双主键如何一次删除多条记录
RT,GridView中有双主键如何一次删除多条记录.

------解决方案--------------------
加checkbox,选中的就删除。
代码如下:

protected void btnDelAll_Click(object sender, EventArgs e)
{
string ids = string.Empty;
foreach (GridViewRow gr in this.gvList.Rows)
{
CheckBox cb = gr.FindControl("chkID") as CheckBox;
if (cb.Checked)
ids += this.gvList.DataKeys[gr.RowIndex].Value + ",";
}
if (!string.IsNullOrEmpty(ids))
{
if (!new ArticleManager().DeleteArticles(ids.Substring(0, ids.Length - 1)))
Page.ClientScript.RegisterStartupScript(GetType(), "success", "<script>alert('删除失败,请重试!');</script>");
else
{
this.gvList.DataSource = new ArticleManager().GetArticles();
this.gvList.DataBind();
}
}
}