protected void GridViewBind()
 {
     FillBlankProblem fillblankproblem = new FillBlankProblem();  //创建填空题对象
     DataSet ds = fillblankproblem.QueryFillBlankProblem(int.Parse(ddlCourse.SelectedValue));//根据试卷科目查询填空题信息
     GridView1.DataSource = ds.Tables[0].DefaultView;    //为GridView控件指名数据源
     GridView1.DataBind();                               //绑定数据
 }
 //显示选择科目的填空题
 protected void ddlCourse_SelectedIndexChanged(object sender, EventArgs e)
 {
     FillBlankProblem fillblankproblem = new FillBlankProblem();  //创建填空题对象
     DataSet ds = fillblankproblem.QueryFillBlankProblem(int.Parse(ddlCourse.SelectedValue));//根据试卷科目查询填空题信息
     GridView1.DataSource = ds.Tables[0].DefaultView;    //为GridView控件指名数据源
     GridView1.DataBind();                               //绑定数据
 }
 //删除试题事件
 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))
     {
         Page.RegisterStartupScript("", "<script language=javascript>alert('成功删除试题!')</script>");
     }
     else
     {
         Page.RegisterStartupScript("", "<script language=javascript>alert('删除试题失败!')</script>");
     }
     GridViewBind();//为GridView重新绑定数据
     GridView1.EditIndex = -1;
 }
 //初始化数据
 protected void InitData()
 {
     int fillblankProblemID = int.Parse(Request["ID"].ToString());  //取出传递过来的试题编号
     FillBlankProblem fillblankproblem = new FillBlankProblem();    //创建填空题对象
     if (fillblankproblem.LoadData(fillblankProblemID))                //如果取出题目信息,分别放在相应控件显示
     {
         ddlCourse.SelectedValue = fillblankproblem.CourseID.ToString();
         ddlDiff.SelectedValue = fillblankproblem.DiffID.ToString();
         txtTitle.Text = fillblankproblem.Title;
         txtAnswer.Text = fillblankproblem.Answer;
     }
     else                //查询出错,给出提示
     {
         lblMessage.Text = "加载数据出错!";
     }
 }
    //添加或修改事件
    protected void imgBtnSave_Click(object sender, ImageClickEventArgs e)
    {
        if (Page.IsValid)
        {
            FillBlankProblem fillblankproblem = new FillBlankProblem();        //创建填空题对象
            fillblankproblem.CourseID = int.Parse(ddlCourse.SelectedValue);//为填空题对象各属性赋值
            fillblankproblem.DiffID = int.Parse(ddlDiff.SelectedValue);//为填空题对象各属性赋值
            fillblankproblem.Title = txtTitle.Text;
            fillblankproblem.Answer = txtAnswer.Text;

            if (Request["ID"] != null)                                  //如果是修改题目信息
            {
                fillblankproblem.ID = int.Parse(Request["ID"].ToString()); //取出试题主键
                if (fillblankproblem.UpdateByProc(int.Parse(Request["ID"].ToString())))//调用修改试题方法修改试题
                {
                    lblMessage.Text = "成功修改该填空题!";
                    txtTitle.Text = "";
                    txtAnswer.Text = "";
                }
                else
                {
                    lblMessage.Text = "修改该填空题失败!";
                }
            }
            else                                                        //如果是添加试题
            {
                if (fillblankproblem.InsertByProc())                       //调用添加试题方法添加试题
                {
                    lblMessage.Text = "成功添加该填空题!";
                    txtTitle.Text = "";
                    txtAnswer.Text = "";
                }
                else
                {
                    lblMessage.Text = "添加该填空题失败!";
                }
            }
        }
    }
 //删除多条记录
 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);
         }
     }
 }
 protected void txtTitle_TextChanged(object sender, EventArgs e)
 {
     FillBlankProblem fbp = new FillBlankProblem();
     if (fbp.isReduplicated(txtTitle.Text.Trim()) == true)
     {
         Page.RegisterStartupScript("", "<script>alert('改题已经存在!');</script>");
         txtTitle.Text = "";
     }
 }