zoukankan      html  css  js  c++  java
  • GridView配合AspNetPager 进行 数据源分页的例子

    很早就知道 可以用 陕西吴起娃 做的 AspNetPager  进行分页

    在以前做的很多项目中也用过  效果不错 不过都是别人写的代码  我没有自己用过

    今天做了一个例子  体验一下:

    前台页面:

    添加引用: <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>

     <webdiyer:AspNetPager ID="pagerNav" runat="server" AlwaysShow="True" ButtonImageNameExtension="n"
                    CpiButtonImageNameExtension="r" CustomInfoText="" DisabledButtonImageNameExtension="g"
                    Height="30" HorizontalAlign="right" ImagePath="../images" InputBoxStyle="border:1px #0000FF solid;text-align:center"
                    NumericButtonTextFormatString="[{0}] " OnPageChanged="pagerNav_PageChanged" PageSize="3"
                    PagingButtonSpacing="0" ShowBoxThreshold="10" ShowCustomInfoSection="left" SubmitButtonStyle="border:1px solid #000066;height:20px;40px"
                    SubmitButtonText="GO" TextAfterInputBox="页" TextBeforeInputBox="转到第" Width="85%"
                    NextPageText='<font face="webdings"></font>' PrevPageText='<font face="webdings"></font>'
                    LastPageText='<font face="webdings"></font>' FirstPageText='<font face="webdings"></font>'>
                </webdiyer:AspNetPager>
               
                <asp:GridView EnableViewState="false" ID="GridView1" PageSize="3" runat="server" AllowPaging="True" AutoGenerateColumns="False">
                    <Columns>
                        <asp:BoundField DataField="sID" HeaderText="sID" SortExpression="sID" />
                        <asp:BoundField DataField="sValue" HeaderText="sValue" SortExpression="sValue" />
                    </Columns>
                    <PagerSettings FirstPageText="首页" LastPageText="末页" NextPageText="&gt;" PreviousPageText="&lt;"
                        PageButtonCount="3" Visible="False" />
                </asp:GridView>

    后台代码:

     protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string sqlConnect = "Provider=SQLOLEDB;data source=HG-J3EJJ9LSW5PY;initial catalog =photomandb_dzrb;User ID=sa;password=hg;Connection Timeout=30";
                DataOperation.globalConnectionString = sqlConnect;
                DataSet ds = DataOperation.SelectDataBySql(@"

    select sID,sValue,row from
    (
      select *,ROW_NUMBER() OVER (ORDER BY sID asc) AS Row from tInfoParameter ) as temp
    where row >=1 and row <=3

    ");

                GridView1.DataSource = ds.Tables[0].DefaultView;
                GridView1.DataBind();

                pagerNav.PageSize = 3;
                pagerNav.CurrentPageIndex = 1;
                pagerNav.RecordCount = 79;
            }

        }


        protected void pagerNav_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
        {

            pagerNav.CurrentPageIndex = e.NewPageIndex;

            string Sql = @"

    select sID,sValue,row from
    (
      select *,ROW_NUMBER() OVER (ORDER BY sID asc) AS Row from tInfoParameter ) as temp
    where row >={0} and row <={1}

    ";
            Sql = string.Format(Sql, e.NewPageIndex * 3 -2 , e.NewPageIndex * 3);
            DataSet ds = DataOperation.SelectDataBySql(Sql);

            GridView1.DataSource = ds.Tables[0].DefaultView;
            GridView1.DataBind();


        }

  • 相关阅读:
    webservice理解
    什么是xmlschema
    web项目中的跨域问题解决方法
    浏览器的同源策略和跨域问题
    java中Scanner和random的用法
    mybatis的批量删除
    java中的异常理解
    事务回滚
    做人做事2个字:心、眼
    Linux下找不到so文件的解决办法
  • 原文地址:https://www.cnblogs.com/zhwl/p/2366137.html
Copyright © 2011-2022 走看看