zoukankan      html  css  js  c++  java
  • 关于AspNetPager的用法(用于个人学习笔记)

    aspx页面代码
     1  <div class="ArticleWrapPage">
     2             <asppager:AspNetPager ID="AspNetPager2" runat="server" HorizontalAlign="Center" PageSize="20"
     3                 FirstPageText="首页" UrlPaging="true" LastPageText="末页" NextPageText="下页" PrevPageText="上页"
     4                 ShowCustomInfoSection="Left" CustomInfoHTML="当前页:<font color='red'><b>%currentPageIndex%</b></font>&nbsp;&nbsp;共 <font color='red'><b>%PageCount%</b></font> 页 当前记录数:%RecordCount%"
     5                 AlwaysShow="True" CloneFrom="AspNetPager1">
     6             </asppager:AspNetPager>
     7         </div>
     8         <div class="ArticleSear">
     9             <asp:Repeater runat="server" ID="repArticleShow">
    10              
    11                 <ItemTemplate>
    12                      <dl><dt><a target="_blank" href='<%=ToUrl %><%#Eval("ARTICLE_ID") %>'>
    13                         <%#TiHuangString(Eval("MAIN_TITLE"))%></a>[<%#Eval("PUBLISH_TIME")%>]</dt>
    14                     <dd>
    15                         <%#TiHuangString(Eval("ARTICLE_CONTENT_PURE"))%>
    16                     </dd> </dl>
    17                 </ItemTemplate>
    18             </asp:Repeater>
    19         </div>
    20         <div class="ArticleWrapPage">
    21             <asppager:AspNetPager ID="AspNetPager1" runat="server" HorizontalAlign="Center" PageSize="20"
    22                 FirstPageText="首页" UrlPaging="true" LastPageText="末页" NextPageText="下页" PrevPageText="上页"
    23                 ShowCustomInfoSection="Left" CustomInfoHTML="当前页:<font color='red'><b>%currentPageIndex%</b></font>&nbsp;&nbsp;共 <font color='red'><b>%PageCount%</b></font> 页 当前记录数:%RecordCount%"
    24                 AlwaysShow="True" OnPageChanged="AspNetPager1_PageChanged">
    25             </asppager:AspNetPager>
    26         </div>
    27     </div>
    Web.config中添加
    1         <pages>
    2             <controls>
    3                 <add tagPrefix="asppager" namespace="Wuqi.Webdiyer" assembly="AspNetPager"/>
    4             </controls>
    5         </pages>

           

    后台代码
     1  protected void Page_Load(object sender, EventArgs e)
     2         {
     3             if (!IsPostBack)
     4             {
     5                 BindCount();
     6             }
     7         }
     8         public string ToUrl = "/News/ArticleDetail.aspx?articleid=";
     9         void Bind()
    10         {
    11 
    12                 AspNetPager1.PageSize = PageSize;
    13                 //AspNetPager1.RecordCount = SearchBLL.AdvSearchCount(MainTitle, FitTitle, Content, KeyWord, SortGroup, Term, DateGroup, SelectDate, StartTime, EndTime, WebSite,Server.UrlDecode(STR_CHANNEL_WEB_CLASS), columnids);
    14                 repArticleShow.DataSource = SearchBLL.AdvSearch(MainTitle, FitTitle, Content, KeyWord, SortGroup, Term, DateGroup, SelectDate, StartTime, EndTime, WebSite, Server.UrlDecode(STR_CHANNEL_WEB_CLASS), columnids, AspNetPager1.StartRecordIndex - 1, PageSize);
    15                 repArticleShow.DataBind();
    16             }
    17         }
    18 
    19 
    20         void BindCount()
    21         {
    22 
    23             if (SearchType)
    24             {
    25                 AspNetPager1.PageSize = 15;
    26                 if (WebSite == 5)
    27                 {
    28                     ToUrl = "/ZwOpenWeb/ZwArticle.aspx?articleid=";
    29                 }
    30                 AspNetPager1.RecordCount = SearchBLL.IndexSearchNewCount(KeyWord, WebSite);
    31                 //repArticleShow.DataSource = SearchBLL.IndexSearch(KeyWord, WebSite, AspNetPager1.StartRecordIndex - 1, AspNetPager1.PageSize);
    32                 //repArticleShow.DataBind();
    33             }
    34             else
    35             {
    36                    AspNetPager1.PageSize = PageSize;
    37                 AspNetPager1.RecordCount = SearchBLL.AdvSearchCount(MainTitle, FitTitle, Content, KeyWord, SortGroup, Term, DateGroup, SelectDate, StartTime, EndTime, WebSite, Server.UrlDecode(STR_CHANNEL_WEB_CLASS), columnids);            }
    38         }
    39 
    40         protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    41         {
    42             Bind();
    43         }

    这里要注意的是UrlPaging的设置,当你设置为true的时候是通过url来传递参数的,那么后台页面每次都会执行PostBack。

    如果设置为false,那么是用表单提交的方式,viewstate里面有保存表单的视图,是属于回发的。

    另外页面每一次重新加载都会触发 OnPageChanged      事件

  • 相关阅读:
    Apache Spark探秘:利用Intellij IDEA构建开发环境
    Scala 安装
    Mac OS Git 安装
    Druid:一个用于大数据实时处理的开源分布式系统
    批量kill Linux环境下的任务
    Xshell如何设置,当连接断开时保留Session,保留原文字
    Superset
    mac连接Windows远程桌面
    IOS应用开发版本控制工具之Versions使用
    “不擅长编码?”-可视化编程插件来解决
  • 原文地址:https://www.cnblogs.com/wenghaowen/p/2674671.html
Copyright © 2011-2022 走看看