2 回答
TA贡献1801条经验 获得超8个赞
参考下列C# 代码:
<PagerTemplate> <table> <tr> <td style="text-align: right"> 第<asp:Label ID="lblPageIndex" runat="server" Text="<%#((GridView)Container.Parent.Parent).PageIndex + 1 %>"></asp:Label>页 共<asp:Label ID="lblPageCount" runat="server" Text="<%# ((GridView)Container.Parent.Parent).PageCount %>"></asp:Label>页 <asp:LinkButton ID="btnFirst" runat="server" CausesValidation="False" CommandArgument="First" CommandName="Page" Text="首页"></asp:LinkButton> <asp:LinkButton ID="btnPrev" runat="server" CausesValidation="False" CommandArgument="Prev" CommandName="Page" Text="上一页"></asp:LinkButton> <asp:LinkButton ID="btnNext" runat="server" CausesValidation="False" CommandArgument="Next" CommandName="Page" Text="下一页"></asp:LinkButton> <asp:LinkButton ID="btnLast" runat="server" CausesValidation="False" CommandArgument="Last" CommandName="Page" Text="尾页"></asp:LinkButton> <asp:TextBox ID="txtNewPageIndex" runat="server" Text="<%# ((GridView)Container.Parent.Parent).PageIndex + 1%>" Width="20px"></asp:TextBox> <asp:LinkButton ID="btnGo" runat="server" CausesValidation="False" CommandArgument="-1" CommandName="Page" Text="GO"></asp:LinkButton> </td> </tr> </table></PagerTemplate>
protected void PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView gvw = (GridView)sender; if (e.NewPageIndex < 0) { TextBox pageNum = (TextBox)gvw.BottomPagerRow.FindControl("txtNewPageIndex"); int Pa = int.Parse(pageNum.Text); if (Pa <= 0) { gvw.PageIndex = 0; } else { gvw.PageIndex = Pa - 1; } } else { gvw.PageIndex = e.NewPageIndex; } GetBind();//你绑定数据的方法 }
TA贡献1824条经验 获得超5个赞
既然很急就用最简单的
一个Gridview控件,AllowPage 属性设为ture
pagechangeing 事件代码(大概)
this.gridview.pageindex=e.newpageindex
page.databind()
一个sqldatasource控件,按照步骤得到相关数据
设置Gridview的数据源为刚建好的SqlDataSource
有Button 的话就用Gridview.Pageindex的这个属性
- 2 回答
- 0 关注
- 3714 浏览
添加回答
举报