Example #1
0
 //添加或修改事件
 protected void imgBtnSave_Click(object sender, ImageClickEventArgs e)
 {
     if (Page.IsValid)
     {
         JudgeProblemmr judgeproblem = new JudgeProblemmr();         //创建判断题对象
         judgeproblem.CourseID = int.Parse(ddlCourse.SelectedValue); //为判断题对象各属性赋值
         judgeproblem.Title    = txtTitle.Text;
         judgeproblem.Answer   = bool.Parse(rblAnswer.SelectedValue);
         if (Request["ID"] != null)                                             //如果是修改题目信息
         {
             judgeproblem.ID = int.Parse(Request["ID"].ToString());             //取出试题主键
             if (judgeproblem.UpdateByStr(int.Parse(Request["ID"].ToString()))) //调用修改试题方法修改试题
             {
                 lblMessage.Text = "成功修改该判断题!";
             }
             else
             {
                 lblMessage.Text = "修改该判断题失败!";
             }
         }
         else                                                      //如果是添加试题
         {
             if (judgeproblem.InsertByStr())                       //调用添加试题方法添加试题
             {
                 lblMessage.Text = "成功添加该判断题!";
             }
             else
             {
                 lblMessage.Text = "添加该判断题失败!";
             }
         }
     }
 }
    protected void GridViewBind()
    {
        JudgeProblemmr judgeproblem = new JudgeProblemmr();                                               //创建判断题对象
        DataSet        ds           = judgeproblem.QueryJudgeProblem(int.Parse(ddlCourse.SelectedValue)); //根据考试科目查询判断题信息

        GridView1.DataSource = ds.Tables[0].DefaultView;                                                  //为GridView控件指名数据源
        GridView1.DataBind();                                                                             //绑定数据
    }
    //显示选择科目的判断题
    protected void ddlCourse_SelectedIndexChanged(object sender, EventArgs e)
    {
        JudgeProblemmr judgeproblem = new JudgeProblemmr();                                               //创建单选题对象
        DataSet        ds           = judgeproblem.QueryJudgeProblem(int.Parse(ddlCourse.SelectedValue)); //根据考试科目查询单选题信息

        GridView1.DataSource = ds.Tables[0].DefaultView;                                                  //为GridView控件指名数据源
        GridView1.DataBind();                                                                             //绑定数据
    }
    //删除多条记录
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        JudgeProblemmr judge = new JudgeProblemmr();          //创建JudgeProblemmr对象

        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.DeleteByStr(ID);
            }
        }
    }
    //删除试题事件
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        JudgeProblemmr judgeproblem = new JudgeProblemmr();                                           //创建判断题对象
        int            ID           = int.Parse(GridView1.DataKeys[e.RowIndex].Values[0].ToString()); //取出要删除记录的主键值

        if (judgeproblem.DeleteByStr(ID))
        {
            Response.Write("<script language=javascript>alert('成功删除试题!')</script>");
        }
        else
        {
            Response.Write("<script language=javascript>alert('删除试题失败!')</script>");
        }
        GridViewBind();//重新绑定数据
        GridView1.EditIndex = -1;
    }
Example #6
0
    //初始化数据
    protected void InitData()
    {
        int            judgeProblemID = int.Parse(Request["ID"].ToString()); //取出传递过来的试题编号
        JudgeProblemmr judgeproblem   = new JudgeProblemmr();                //创建判断题对象

        if (judgeproblem.LoadData(judgeProblemID))                           //如果取出题目信息,分别放在相应控件显示
        {
            ddlCourse.SelectedValue = judgeproblem.CourseID.ToString();
            txtTitle.Text           = judgeproblem.Title;
            rblAnswer.SelectedValue = judgeproblem.Answer.ToString();
        }
        else                //查询出错,给出提示
        {
            lblMessage.Text = "加载数据出错!";
        }
    }