//删除多条记录 protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { FillBlankProblem fill = new FillBlankProblem();//创建FillBlankProblem对象 foreach (GridViewRow dr in GridView1.Rows)//对GridView中的每一行进行判断 { if (((CheckBox)dr.FindControl("xuanze")).Checked)//如果选择了进行删除 { int ID = int.Parse(((Label)dr.FindControl("Label1")).Text); fill.ID = ID; fill.DeleteByProc(ID); } } Response.AddHeader("Refresh", "0"); }
//删除试题事件 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { FillBlankProblem fillblankproblem = new FillBlankProblem(); //创建填空题对象 int ID = int.Parse(GridView1.DataKeys[e.RowIndex].Values[0].ToString()); //取出要删除记录的主键值 if (fillblankproblem.DeleteByProc(ID)) { Response.Write("<script language=javascript>alert('成功删除试题!')</script>"); } else { Response.Write("<script language=javascript>alert('该题已被收录入试卷,请勿删除!')</script>"); } GridViewBind();//为GridView重新绑定数据 GridView1.EditIndex = -1; }