关于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      事件

posted @ 2012-09-07 10:41  天殇月痕  阅读(210)  评论(0编辑  收藏  举报