コード例 #1
0
 private void Page_Load(object sender, System.EventArgs e)
 {
     // 在此处放置用户代码以初始化页面
     if (!IsPostBack)
     {
         MyMethods mm = new MyMethods();
         if (Session["Teacher_ID"] == null)
         {
             mm.AlertAndRedirect("您尚未登录!", "/test/login.aspx");
             return;
         }
         lbl_Title.Text = "系部班级管理";
         BtnSave.Attributes.Add("OnClick", "JavaScript:return confirm('您真要保存吗?')");
         BtnSaveBj.Attributes.Add("OnClick", "JavaScript:return confirm('您真要保存吗?')");
         mm.DG_bind(Dg_xb, "select * from 系部", "", "", Application["connstr"].ToString());
     }
 }
 private void Page_Load(object sender, System.EventArgs e)
 {
     // 在此处放置用户代码以初始化页面
     if (!IsPostBack)
     {
         MyMethods mm = new MyMethods();
         if (Session["Teacher_ID"] == null)
         {                 //验证教师是否登录
             mm.AlertAndRedirect("您尚未登录!", "/test/login.aspx");
             return;
         }
         if (Session["tixing"] == null)              //设置默认显示的题型
         {
             Session["tixing"] = "单选题";
         }
         if (Session["curr_page"] == null)
         {
             Session["curr_page"] = "0";                  //记录当前DataGrid的当前页,使的从题库录入页面中编辑后返回该页时仍然能够回到当前页
         }
         if (Session["sort_field"] == null)
         {
             Session["sort_field"] = "题干";              //设置DataGrid默认排序字段
         }
         if (Session["sort_direction"] == null)
         {
             Session["sort_direction"] = "ASC";                  //设置DataGrid默认排序方向
         }
         if (Session["ddlselectedvalue"] == null)
         {
             Session["ddlselectedvalue"] = "";                  //如果用户使用了检索功能,该Session用于记录用户的检索条件,以便从题库录入页面中编辑后返回该页时仍然能够显示刚才检索结果
         }
         if (Session["ddlselectedtext"] == null)
         {
             Session["ddlselectedtext"] = "";                  //与上面的Session一样记录检索条件的,但是以中文形式显示在页面第二行的ListBox控件中的文字
         }
         lbl_Title.Text          = "题库列表";
         DDLtixing.SelectedValue = Convert.ToString(Session["tixing"]);
         set_datagrid_visible(Convert.ToString(Session["tixing"]));;                                  //该方法设置各DataGrid可见属性,只有参数传入的题型所在的DataGrid才可见
         DataGrid curr_dg = (DataGrid)this.FindControl(find_DG(Convert.ToString(Session["tixing"]))); //获取当前题型所对应的DataGrid,find_DG方法返回当前参数所代表的题型所对应的DataGrid的ID
         curr_dg.CurrentPageIndex = Convert.ToInt16(Session["curr_page"]);                            //将该DataGrid的当前页码设置为Session["curr_page"]中存储的页码
         DG_bind();                                                                                   //调用自定义函数,执行对DataGrid的绑定显示操作
     }
 }