//GridView控件绑定数据事件
 protected void GridViewBind()
 {
     QuestionProblem questionproblem = new QuestionProblem();  //创建单选题对象
     DataSet ds = questionproblem.QueryQuestionProblem(int.Parse(ddlCourse.SelectedValue));//根据试卷科目查询问答题信息
     GridView1.DataSource = ds.Tables[0].DefaultView;    //为GridView控件指名数据源
     GridView1.DataBind();                               //绑定数据
 }
 //添加或修改事件
 protected void imgBtnSave_Click(object sender, ImageClickEventArgs e)
 {
     if (Page.IsValid)
     {
         QuestionProblem questionproblem = new QuestionProblem();          //创建单选题对象
         questionproblem.CourseID = int.Parse(ddlCourse.SelectedValue);//为单选题对象各属性赋值
         questionproblem.DiffID = int.Parse(ddlDiff.SelectedValue);//为填空题对象各属性赋值
         questionproblem.Title = txtTitle.Text;
         questionproblem.Answer = txtAnswer.Text;
         if (Request["ID"] != null)                                  //如果是修改题目信息
         {
             questionproblem.ID = int.Parse(Request["ID"].ToString()); //取出试题主键
             if (questionproblem.UpdateByProc(int.Parse(Request["ID"].ToString())))//调用修改试题方法修改试题
             {
                 lblMessage.Text = "成功修改该问答题!";
             }
             else
             {
                 lblMessage.Text = "修改该问答题失败!";
             }
         }
         else                                                        //如果是添加试题
         {
             if (questionproblem.InsertByProc())                       //调用添加试题方法添加试题
             {
                 lblMessage.Text = "成功添加该问答题!";
             }
             else
             {
                 lblMessage.Text = "添加该问答题失败!";
             }
         }
     }
 }
 //删除多条记录
 protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
 {
     QuestionProblem question = new QuestionProblem();//创建SingleProblem对象
     foreach (GridViewRow dr in GridView1.Rows)//对GridView中的每一行进行判断
     {
         if (((CheckBox)dr.FindControl("xuanze")).Checked)//如果选择了进行删除
         {
             int ID = int.Parse(((Label)dr.FindControl("Label1")).Text);
             question.ID = ID;
             question.DeleteByProc(ID);
         }
     }
 }
 //删除试题事件
 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     QuestionProblem questionproblem = new QuestionProblem();  //创建问答题对象
     int ID = int.Parse(GridView1.DataKeys[e.RowIndex].Values[0].ToString()); //取出要删除记录的主键值
     if (questionproblem.DeleteByProc(ID))
     {
         Response.Write("<script language=javascript>alert('成功删除试题!')</script>");
     }
     else
     {
         Response.Write("<script language=javascript>alert('删除试题失败!')</script>");
     }
     GridView1.EditIndex = -1;
     GridViewBind();//重新绑定数据
 }
 //初始化数据
 protected void InitData()
 {
     int QuestionProblemID = int.Parse(Request["ID"].ToString());  //取出传递过来的试题编号
     QuestionProblem questionproblem = new QuestionProblem();          //创建单选题对象
     if (questionproblem.LoadData(QuestionProblemID))                //如果取出题目信息,分别放在相应控件显示
     {
         ddlCourse.SelectedValue = questionproblem.CourseID.ToString();
         ddlDiff.SelectedValue = questionproblem.DiffID.ToString();
         txtTitle.Text = questionproblem.Title;
         txtAnswer.Text = questionproblem.Answer;
     }
     else                //查询出错,给出提示
     {
         lblMessage.Text = "加载数据出错!";
     }
 }