基于上次看了CodeProject的一篇文章后,
 很多刚学习.net的朋友们都向我咨询一些该如何分页的问题.于是萌发想写一篇教导初学者如何分页的文章

 1、  DataGrid本身提供的分页方式

     该方式简单易用,缺点效率有点差

   实现方法如下

第一步,从工具箱Web窗体〉拖拉出DataGrid控件,设置其属性

AllowPaging="True"

PageSize="20"

Html代码效果如下

 ArrayManage.aspx

<asp:DataGrid >

<PagerStyle Mode="NumericPages"></PagerStyle>

</asp:DataGrid>

 

第二步 双击该窗体,进入codebehide

 private void Page_Load(object sender, System.EventArgs e)

         {

              // 在此处放置用户代码以初始化页面

                   if(!Page.IsPostBack)

              {

                       BindData();

              }

         }

 private void BindData()

         {

            SqlConnectionConn = new SqlConnection();

              Conn.ConnectionString =@"server=MIS\PMSERVER;uid=sa;pwd=sa;database=test";

                   Conn.Open();

                   string strSql = "select  typeId,typename from type_Info ";

                   DataSet ds = new DataSet();

                   SqlDataAdapter Adp = new SqlDataAdapter(strSql,Conn);

                   Adp.Fill(ds,"TypeIdList");

                this.DataGrid1.DataSource= ds.Tables[0];

               this.DataGrid1.DataBind();

         }

private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)

         {

              DataGrid1.CurrentPageIndex = e.NewPageIndex;

              BindData();
}

相关文章:

  • 2021-12-11
  • 2022-02-17
  • 2021-08-07
  • 2021-11-03
  • 2022-12-23
  • 2022-12-23
  • 2021-07-03
猜你喜欢
  • 2022-12-23
  • 2022-02-09
  • 2022-12-23
  • 2022-01-09
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案