GridView分页问题?

weilong147247943 2008-10-15 10:16:49
<PagerTemplate>
<asp:LinkButton ID="lbFirst" runat="server" CausesValidation="False" CommandArgument="First"
CommandName="Page">首页</asp:LinkButton>
<asp:LinkButton ID="lbPrev" runat="server" CausesValidation="False" CommandArgument="Prev"
CommandName="Page">上一页</asp:LinkButton>
<asp:LinkButton ID="lbNext" runat="server" CausesValidation="False" CommandArgument="Next"
CommandName="Page">下一页</asp:LinkButton>
<asp:LinkButton ID="lbLast" runat="server" CausesValidation="False" CommandArgument="Last"
CommandName="Page">尾页</asp:LinkButton> 第<asp:Label ID="Label2"
runat="server" Text="<%#((GridView)Container.Parent.Parent).PageIndex + 1 %>"></asp:Label>页
共<asp:Label ID="Label1" runat="server" Text="<%# ((GridView)Container.Parent.Parent).PageCount %>"></asp:Label>页
跳到<asp:TextBox ID="tbPage" runat="server" Text="<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>"
Width="27px"></asp:TextBox>
<asp:LinkButton ID="lbGO" runat="server" CausesValidation="False" CommandArgument="-1"
CommandName="Page" Text="GO"></asp:LinkButton>
</PagerTemplate>
分页事件
protected void borrowGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView gvw = (GridView)sender;

if (e.NewPageIndex < 0)
{
TextBox pageNum = (TextBox)gvw.BottomPagerRow.FindControl("tbpage");

int Pa = int.Parse(pageNum.Text);
if (Pa <= 0)
gvw.PageIndex = 0;
else
gvw.PageIndex = Pa - 1;

}
else
{
gvw.PageIndex = e.NewPageIndex;
}

borrowGridView.DataSource = sa.selAssertBorrow();
borrowGridView.DataBind();
}
    首页 上一页 下一页 尾页 第?页 共?页 跳到?页GO
帮忙修改一下代码,要实现在第一页的时候"首页"和"上一页"不可用,在最后一页的时候"尾页"和"下一页"不可用,点GO的时候不能跳到要指定到的页。 谢谢拉!
...全文
171 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
weilong147247943 2008-10-15
  • 打赏
  • 举报
回复
 恩,一般都用分页控件了吧!
   现在我要实现这个,帮忙解决!
amandag 2008-10-15
  • 打赏
  • 举报
回复
很少有人用GridView自带的分页了..
birdlonger 2008-10-15
  • 打赏
  • 举报
回复
mark!
y51704545 2008-10-15
  • 打赏
  • 举报
回复
收藏
weilong147247943 2008-10-15
  • 打赏
  • 举报
回复
谢谢,前面那个问题解决了,但是那个跳转没实现,能不能帮忙再看一下,帮我解决解决!
wuyq11 2008-10-15
  • 打赏
  • 举报
回复
<asp:LinkButton ID="lbFirst" runat="server" CausesValidation="False" CommandArgument="First"
CommandName="Page" Visible='<%#((GridView)Container.NamingContainer).PageIndex != 0 %>'>首页 </asp:LinkButton>
<asp:LinkButton ID="lbPrev" runat="server" CausesValidation="False" CommandArgument="Prev"
CommandName="Page" Visible='<%#((GridView)Container.NamingContainer).PageIndex != 0 %>'>上一页 </asp:LinkButton>
<asp:LinkButton ID="lbNext" runat="server" CausesValidation="False" CommandArgument="Next"
CommandName="Page" Visible='<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>'>下一页 </asp:LinkButton>
<asp:LinkButton ID="lbLast" runat="server" CausesValidation="False" CommandArgument="Last"
CommandName="Page" Visible='<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>'>尾页 </asp:LinkButton>


weilong147247943 2008-10-15
  • 打赏
  • 举报
回复
会报错误,
提示上下文中找不到pagerRow的定义!
wuyq11 2008-10-15
  • 打赏
  • 举报
回复
把我写的代码放在if (e.NewPageIndex < 0) 里
suen.sun 2008-10-15
  • 打赏
  • 举报
回复
给按钮加个CommandName,值设置为“Jump”什么的,在分页事件面判断这个值e.CommandName=="Jump"就按照输入的页数进行翻页。OK!
不过现在都流行自定义分页控件了。呵呵,自己写一个吧!

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧