zoukankan      html  css  js  c++  java
  • 使用分页控件AspNetPager分页

    一、创建AspNetPager对象
    <webdiyer:AspNetPager id="page"  runat="server"
    PrevPageText="上页" NextPageText="下页" LastPageText="尾页" FirstPageText="首页" SubmitButtonText="转到" ShowInputBox="Always"
    PageSize="2" CustomInfoSectionWidth="50%" ShowCustomInfoSection="Left">
    </webdiyer:AspNetPager>

    <asp:Label Runat=server ID=lblMsg  Visible=False></asp:Label>
    二、添加后台代码
    1.导入名称空间,using System.Data.SqlClient;或using System.Data.OleDbClient;定义一个变量flag,标识是否有符合条件的记录。
    2.写方法:第一次加载数据,重新加载数据。
    protected int flag;
    private void Page_Load(object sender, System.EventArgs e)
      {
       if(!this.IsPostBack)
       {
        SqlConnection conn=new SqlConnection(DAL.SQLHelper.CONN_STRING);
        conn.Open();
        SqlCommand com=new SqlCommand("select count(*) from tbl_serverice",conn);
        page.RecordCount=Convert.ToInt32(com.ExecuteScalar());
       
        flag=page.RecordCount;
     
        Bind();
        if(flag==0)
       {
        this.lblMsg.Text="没有找到符合条件的相关记录";
        this.lblMsg.Visible=true;
       }
       else
       {
         this.lblMsg.Visible=false;
       }
       }

       
       
      }


    void Bind()
      {
       SqlConnection conn=new SqlConnection(DAL.SQLHelper.CONN_STRING);
       conn.Open();
       SqlDataAdapter ada=new SqlDataAdapter("select * from tbl_serverice where serv_id=1212",conn);
       DataSet ds=new DataSet();
       

       //先加载部分数据
       // ACda.Fill(ACds,haha.PageSize*(haha.CurrentPageIndex-1),haha.PageSize,"CurDataTable");

       ada.Fill(ds,page.PageSize*(page.CurrentPageIndex-1),page.PageSize,"curdata");
       ada.Fill(ds,"alldata");

       //this.dg.VirtualItemCount=ds.Tables["alldata"].Rows.Count;//DataGrid须用此句程式
       this.flag=ds.Tables["alldata"].Rows.Count;

       this.dlServAdv.DataSource=ds.Tables["curdata"];
       this.dlServAdv.DataBind();

       page.CustomInfoText=" 共有记录<font color=\"blue\"><b>"+page.RecordCount.ToString()+"</b></font>条";
       page.CustomInfoText+=" 共有<font color=\"blue\"><b>"+page.PageCount.ToString()+"</b></font>页";
       page.CustomInfoText+=" 当前为第<font color=\"red\"><b>"+page.CurrentPageIndex.ToString()+"</b></font>页";
       conn.Dispose();
       ada.Dispose();
      }

    private void AspNetPager1_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
      {
       page.CurrentPageIndex=e.NewPageIndex;
       this.Bind();
      }


     

    人的一生应该这样度过:当他回首往事的时候,不会因为虚度年华而悔恨,也不会因为碌碌无为而羞愧。
  • 相关阅读:
    【C++基础汇总】参数传递
    常用VC快捷键
    美股交易规则
    xpath 总结1
    【字符集】字符集和编码知识【转】
    【字符集】ASCII 表
    【win32编程学习】常用技巧总结
    【win32编程学习】 调用dll
    【win32编程学习】 创建自己的dll
    充实的生活
  • 原文地址:https://www.cnblogs.com/htht66/p/883739.html
Copyright © 2011-2022 走看看