C# 中 如何分页
2013-11-30
展开全部
利用GridView分页模版进行分页<asp:GridView ID="gvArticleInfo" runat="server" AutoGenerateColumns="False" Width="98%" DataKeyNames="BlID" AllowPaging="True" PageSize="2" OnPageIndexChanging="gvArticleInfo_PageIndexChanging" BorderWidth="1px" EnableModelValidation="True">
<RowStyle Height="30px" />
<Columns> <!--列内容-->
</Columns>
<PagerTemplate>
<table width="100%">
<tr>
<td valign="bottom" style="height:35px;">
共:<asp:Label ID="lblCount" runat="server" Text='<%#((GridView)Container.Parent.Parent).PageCount %>' ForeColor="Red" Font-Bold="true"></asp:Label>页
当前第:<asp:Label ID="lblThisPage" runat="server" Text='<%#((GridView)Container.Parent.Parent).PageIndex+1 %>' ForeColor="Red" Font-Bold="true"></asp:Label>页
<asp:Label ID="lblPageCount" runat="server" Text="15" Font-Bold="true" ForeColor="Black"></asp:Label>条记录/页
<asp:LinkButton ID="hlFirst" runat="server" CommandName="Page" CommandArgument="First" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=0 %>">首 页</asp:LinkButton>
<asp:LinkButton ID="hlUpPage" runat="server" CommandName="Page" CommandArgument="Prev" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=0 %>">上一页</asp:LinkButton>
<asp:LinkButton ID="hlNextPage" runat="server" CommandName="Page" CommandArgument="Next" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1 %>">下一页</asp:LinkButton>
<asp:LinkButton ID="hlEnd" runat="server" CommandName="Page" CommandArgument="Last" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1 %>">尾 页</asp:LinkButton>
<asp:TextBox ID="txtGO" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageIndex+1 %>' Width="32px"></asp:TextBox>页
<asp:Button ID="btnGO" runat="server" Text="转到" onclick="btnGO_Click" />
</td>
</tr>
</table>
</PagerTemplate>
<PagerStyle HorizontalAlign="Center" /></asp:GridView> protected void btnGO_Click(object sender, EventArgs e)
{
gvArticleInfo.PageIndex = int.Parse(((TextBox)gvArticleInfo.BottomPagerRow.FindControl("txtGO")).Text) - 1;
DataBinder();
}private void DataBinder()
{
DataTable table = ArticleInfoManager.GetAllArticleInfo();
gvArticleInfo.DataSource = table;
gvArticleInfo.DataBind();
}protected void gvArticleInfo_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvArticleInfo.PageIndex = e.NewPageIndex;
DataBinder();
}
<RowStyle Height="30px" />
<Columns> <!--列内容-->
</Columns>
<PagerTemplate>
<table width="100%">
<tr>
<td valign="bottom" style="height:35px;">
共:<asp:Label ID="lblCount" runat="server" Text='<%#((GridView)Container.Parent.Parent).PageCount %>' ForeColor="Red" Font-Bold="true"></asp:Label>页
当前第:<asp:Label ID="lblThisPage" runat="server" Text='<%#((GridView)Container.Parent.Parent).PageIndex+1 %>' ForeColor="Red" Font-Bold="true"></asp:Label>页
<asp:Label ID="lblPageCount" runat="server" Text="15" Font-Bold="true" ForeColor="Black"></asp:Label>条记录/页
<asp:LinkButton ID="hlFirst" runat="server" CommandName="Page" CommandArgument="First" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=0 %>">首 页</asp:LinkButton>
<asp:LinkButton ID="hlUpPage" runat="server" CommandName="Page" CommandArgument="Prev" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=0 %>">上一页</asp:LinkButton>
<asp:LinkButton ID="hlNextPage" runat="server" CommandName="Page" CommandArgument="Next" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1 %>">下一页</asp:LinkButton>
<asp:LinkButton ID="hlEnd" runat="server" CommandName="Page" CommandArgument="Last" Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1 %>">尾 页</asp:LinkButton>
<asp:TextBox ID="txtGO" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageIndex+1 %>' Width="32px"></asp:TextBox>页
<asp:Button ID="btnGO" runat="server" Text="转到" onclick="btnGO_Click" />
</td>
</tr>
</table>
</PagerTemplate>
<PagerStyle HorizontalAlign="Center" /></asp:GridView> protected void btnGO_Click(object sender, EventArgs e)
{
gvArticleInfo.PageIndex = int.Parse(((TextBox)gvArticleInfo.BottomPagerRow.FindControl("txtGO")).Text) - 1;
DataBinder();
}private void DataBinder()
{
DataTable table = ArticleInfoManager.GetAllArticleInfo();
gvArticleInfo.DataSource = table;
gvArticleInfo.DataBind();
}protected void gvArticleInfo_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvArticleInfo.PageIndex = e.NewPageIndex;
DataBinder();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-11-30
展开全部
aspnetpager控件很不错,推荐一下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询