自定义GridView分页模板中页码Button的实现(上)

 

第一次使用ASP.NET,遇到的问题实在太多了,前几天想要实现GridView中的分页效果,知道了自带的PagerSettings功能,但是发现它不能同时有上下页和页码的功能,后来知道了PagerTemplate自定义模板的功能,根据以下文章的方法进行了设置:

    自定义GridView分页模板

代码如下:可以利用linkbutton 的参数commandargument和commandname来实现上下页和首尾页的功能。

<PagerTemplate>
<table width="100%">
<tr>
<td style="text-align: right">
<asp:Label ID="lblPageIndex" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />页
共/
<asp:Label ID="lblPageCount" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageCount %>' />页
<asp:LinkButton ID="btnFirst" runat="server" CausesValidation="False" CommandArgument="First"
CommandName
="Page" Text="首页" />
<asp:LinkButton ID="btnPrev" runat="server" CausesValidation="False" CommandArgument="Prev"
CommandName
="Page" Text="上一页" />
<asp:LinkButton ID="btnNext" runat="server" CausesValidation="False" CommandArgument="Next"
CommandName
="Page" Text="下一页" />
<asp:LinkButton ID="btnLast" runat="server" CausesValidation="False" CommandArgument="Last"
CommandName
="Page" Text="尾页" />
<asp:TextBox ID="txtNewPageIndex" runat="server" Width="20px" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />
<asp:LinkButton ID="btnGo" runat="server" CausesValidation="False" CommandArgument="-1"
CommandName
="Page" Text="GO" /><!-- here set the CommandArgument of the Go Button to '-1' as the flag -->
</td>
</tr>
</table>
</PagerTemplate>

 

 
 

     但是还是没有页码的按钮,然后我用了如下的方法,在模板中用FOR添加了多个commandargument为数字的linkbutton 。这样在效果上是有了页码按钮了,可是点击的参数总是为空的,也就是说CommandArgument="<%=i+1 %>" 中不可以用<%=%>来调用i的值,可是使用Response.Write的方法有不可以写asp的控件,那如何可以将这个页号的参数传到后台呢?

Code
。。。
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandArgument="Prev" CommandName="Page" Text="上一页" />
<% for (int i = 0; i <= this.grvPage.PageCount; i++)
{
if (i == this.grvPage.PageIndex)
Response.Write(
"<span style='background-color:Blue; color:#ffffff'>" + (i+1) + "</span>");
else %>
<asp:LinkButton runat="server" CausesValidation="False" CommandArgument="<%=i+1 %>" CommandName="Page" ><%=i+1 %></asp:LinkButton>
<% Response.Write("&nbsp;");
}
%>
<asp:LinkButton ID="btnNext" runat="server" CausesValidation="False" CommandArgument="Next" CommandName="Page" Text="下一页" />
。。。

     呵呵,当然,最后还是没有找到方法。不过这里用了另外的一种方法实现了效果,就是页面GET(QueryString)传数据的方法。下面是效果图。

[1] [2]

转载于:https://www.cnblogs.com/hxuan999/archive/2008/12/03/1346978.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值