//显示选择科目的判断题
 protected void ddlCourse_SelectedIndexChanged(object sender, EventArgs e)
 {
     JudgeProblem judgeproblem = new JudgeProblem();  //创建单选题对象
     DataSet ds = judgeproblem.QueryJudgeProblem(Int32.Parse(ddlCourse.SelectedValue));//根据考试科目查询单选题信息
     GridView1.DataSource = ds.Tables[0].DefaultView;    //为GridView控件指名数据源
     GridView1.DataBind();                               //绑定数据
 }
 //删除多条记录
 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);
         }
     }
     this.GridView1.DataBind();
 }
 //删除试题事件
 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))
     {
         Response.Write("<script language=javascript>alert('成功删除试题!')</script>");
     }
     else
     {
         Response.Write("<script language=javascript>alert('该题已被收录入试卷,请勿删除!')</script>");
     }
     GridViewBind();//重新绑定数据
     GridView1.EditIndex = -1;
 }
    //初始化数据
    protected void InitData()
    {
        int judgeProblemID = int.Parse(Request["ID"].ToString());   //取出传递过来的试题编号
        JudgeProblem judgeproblem = new JudgeProblem();             //创建判断题对象
        if (judgeproblem.LoadData(judgeProblemID))                  //如果取出题目信息,分别放在相应控件显示
        {
            ddlCourse.SelectedValue = judgeproblem.CourseID.ToString();
            txtTitle.Text = judgeproblem.Title;
            rblAnswer.SelectedValue = judgeproblem.Answer.ToString();

        }
        else                //查询出错,给出提示
        {
            lblMessage.Text = "加载数据出错!";
        }
    }
    //添加或修改事件
    protected void imgBtnSave_Click(object sender, ImageClickEventArgs e)
    {
        if (Page.IsValid)
        {
            JudgeProblem judgeproblem = new JudgeProblem();          //创建判断题对象
            judgeproblem.CourseID = int.Parse(ddlCourse.SelectedValue);//为判断题对象各属性赋值

            //程军添加,判断题题目不能超过1000个字符,自动截取前1000个字符.2010-4-26;
            if (txtTitle.Text.Length > 1000)
            {
                this.Label1.Visible = true;
                this.Label1.Text = "题干不能超过1000字符,自动截取前1000字符";
                judgeproblem.Title = txtTitle.Text.Substring(0, 1000);
            }
            else
            {
                judgeproblem.Title = txtTitle.Text;
            }
            //程军添加,判断题题目不能超过1000个字符,自动截取前1000个字符.2010-4-26;

            //judgeproblem.Title = txtTitle.Text;
            judgeproblem.Answer = bool.Parse(rblAnswer.SelectedValue);
            if (Request["ID"] != null)                                  //如果是修改题目信息
            {
                judgeproblem.ID = int.Parse(Request["ID"].ToString()); //取出试题主键
                if (judgeproblem.UpdateByProc(int.Parse(Request["ID"].ToString()), int.Parse(ddlCourse.SelectedValue)))//调用修改试题方法修改试题
                {
                    lblMessage.Text = "成功修改该判断题!";
                }
                else
                {
                    lblMessage.Text = "修改该判断题失败!";
                }
            }
            else                                                        //如果是添加试题
            {
                if (judgeproblem.InsertByProc(int.Parse(ddlCourse.SelectedValue)))                       //调用添加试题方法添加试题
                {
                    lblMessage.Text = "成功添加该判断题!";
                }
                else
                {
                    lblMessage.Text = "添加该判断题失败!";
                }
            }
        }
    }
    protected void GridViewBind()
    {
        JudgeProblem judgeproblem = new JudgeProblem();  //创建判断题对象
        DataSet ds = judgeproblem.QueryJudgeProblem(Int32.Parse(ddlCourse.SelectedValue));//根据考试科目查询判断题信息
        GridView1.DataSource = ds.Tables[0].DefaultView;    //为GridView控件指名数据源
        GridView1.DataBind();                               //绑定数据

        //胡媛媛修改,为gridview1中的复选框添加事件,2010-5-5
        if (GridView1.Rows.Count > 0)
        {
            foreach (GridViewRow dr in GridView1.Rows)
            {
                ((CheckBox)dr.FindControl("xuanze")).Attributes.Add("onclick", "SigchkChg()");
            }
        }
        //胡媛媛修改,为gridview1中的复选框添加事件,2010-5-5
    }