zoukankan      html  css  js  c++  java
  • .Net 分页实现系列之一 DataGrid本身提供的分页方式

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

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

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

       实现方法如下

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

    AllowPaging="True"

    PageSize="20"

    Html代码效果如下

     ArrayManage.aspx

    <asp:DataGrid id="DataGrid1" runat="server" CssClass="SolidDataGrid" singleValue="#F7F7F7" oldValue="#FFFFFF" DataKeyField="GroupId" Width="98%" AutoGenerateColumns="False" AllowPaging="True" PageSize="20">

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

    </asp:DataGrid>

     

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

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

             {

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

                       if(!Page.IsPostBack)

                  {

                           BindData();

                  }

             }

     private void BindData()

             {

                SqlConnection Conn = 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();
    }

  • 相关阅读:
    ARCGIS JAVASCRIPT API (3.2)部署
    WINFORM 只能运行一个实例问题
    iOS 版本号
    同步和异步的区别
    简单的手机号判断
    "_inflateEnd", referenced from "_inflateInit_"等。这时需要在工程中加入libz.dlib 文件
    iOS 实现打电话
    assign retain copy iOS
    iOS 长按事件 UILongPressGestureRecognizer
    UITableView 滑动删除
  • 原文地址:https://www.cnblogs.com/meetweb/p/316630.html
Copyright © 2011-2022 走看看