ASP.NET技巧:GridView控件自定义分页详解
日期:2007年9月11日 作者: 查看:[大字体 中字体 小字体]
-
border="0" marginwidth="0" marginheight="0" src="http://www.hackhome.com/gg/web/ff_468.html" frameborder="no" width="468" scrolling="no" height="0"> - <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script> name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-0692289505803928&dt=1206920732000&lmt=1199925151&format=300x250_as&output=html&correlator=1206920732000&channel=6926205886&url=http%3A%2F%2Fwww.hackhome.com%2FInfoView%2FArticle_180198.html&color_bg=FFFFFF&color_text=000000&color_link=000060&color_url=008000&color_border=FFFFFF&ad_type=text_image&ref=http%3A%2F%2Fwww.hackhome.com%2FInfoView%2FArticle_152410_3.html&frm=0&cc=100&ga_vid=702123880.1206920732&ga_sid=1206920732&ga_hid=2142913223&flash=9.0.47.0&u_h=768&u_w=1024&u_ah=738&u_aw=1024&u_cd=32&u_tz=480&u_java=true" frameborder="0" width="300" scrolling="no" height="250" allowtransparency="allowtransparency">
前些天我写了关于 <<在存储过程中实现分页>>和<<GridView控件事件详解 >> ,后来又有一些人问我怎样在GridView中应用这个东东!其实很简单,主要是怎么保存当前页面的页码PageIndex问题,不过把这个解决了什么都好办了.因为在分页过程中:PageSize是一定的,我们可以用一个属性来表示.保存PageIndex好多中方法,而且数据不是很庞大,基本不会好太多的资源.还是一句老话,话再多都没有例子直观.
在这里我们将用一个隐藏字段来保存这个PageIndex,即当前页码.当点击上一页时,将它的值减一,知道为0,要注意的一点这里的第一页页码是0而不是1.下面看看代码,然后我们再分析分析!
1<ASP:GridView ID="NewsGrid" runat="server" AutoGenerateColumns="False" AllowPaging="false" Width="100%">
2 <Columns>
3 <asp:BoundField DataField="NewsId" HeaderText="新闻ID"/>
4 <asp:HyperLinkField DataNavigateUrlFields="NewsId" DataNavigateUrlFormatString="~/Details.aspx?ID={0}"
5 DataTextField="Title" HeaderText="新闻标题" ItemStyle-Width="70%"/>
6 <asp:BoundField DataField="PostTime" HeaderText="发布时间"/>
7 <asp:CommandField HeaderText="新闻管理" ShowCancelButton="False" ShowDeleteButton="True"
8 ShowEditButton="True"/>
9 </Columns>
10 </asp:GridView>