aspnetpager控件的绑定

来源:互联网 发布:淘宝欧米茄碟飞翻新表 编辑:程序博客网 时间:2024/05/17 06:07


    public partial class DisciplineTeamInfo : System.Web.UI.Page
    {
        DAL.DisciplineTeamInfo da = new DAL.DisciplineTeamInfo();
        protected void Page_Init(object sender, EventArgs e)
        {
            DataSet ds = da.GetAll();  //得到全部数据
            DataList1.DataSource = ds;  //绑定datalist默认值
            DataList1.DataBind();
            this.AspNetPager1.PageSize = 10; //设置每也显示的记录条数
            this.AspNetPager1.CurrentPageIndex = 1;  //第一次显示的索引
        }
        protected void lbtn_del_Command(object sender, CommandEventArgs e)
        {
            M.DisciplineTeamInfo mod = new MODEL.DisciplineTeamInfo();
            mod.TeacherNO = Convert.ToString(e.CommandArgument);

            DAL.DisciplineTeamInfo da = new DAL.DisciplineTeamInfo();
            da.delete(mod);
            DataSet ds = da.GetAll();
            DataList1.DataSource = ds;
            DataList1.DataBind();
        }

        protected void btn_select_Click(object sender, EventArgs e)
        {

            string valu = txt_select.Text;
            string fild = drp_lx.SelectedValue.ToString();
            if (drp_lx.SelectedValue.ToString() == "quanbu")
            {
                //DataSet ds = da.GetAll();
                //DataList1.DataSource = ds;
                // DataList1.DataBind();
                Bind();
            }
            else
            {
                //  DataSet ds = da.GetAll(valu, "selid", fild);
                // DataList1.DataSource = ds;
                // DataList1.DataBind();
                Session["bz"] = 2;
                Bind();
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) //回发事件,只执行一次
            {
                Session["bz"] = 1;
                if (Convert.ToInt32(Session["bz"]) == 1)
                {
                    AspNetPager1.RecordCount = da.count(); //控件的总记录数
                    Bind();
                }
            }
        }
         private void Bind()
        {
            PagedDataSource pds = new PagedDataSource(); //控件的数据源
            pds.AllowPaging = true;                   //是否小于两页还显示控件,true为一直显示
            pds.PageSize = AspNetPager1.PageSize;     //每页的记录数
            pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
            if (Convert.ToInt32(Session["bz"]) == 1)
              {

            pds.DataSource = da.GetAll().Tables[0].DefaultView;

            DataList1.DataSource = pds;
            DataList1.DataBind();
            }
            else
            {
                string valu = txt_select.Text;
                string fild = drp_lx.SelectedValue.ToString();
                pds.DataSource = da.GetAll(valu, "selid", fild).Tables[0].DefaultView;
                AspNetPager1.RecordCount = da.count(valu, "count1", fild);
                DataList1.DataSource = pds;
                DataList1.DataBind();
            }

        }
           protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
          
            Bind();
       
        }

    }

 

原创粉丝点击