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