gridview如何分页控制显示的行数?大虾帮帮忙
5个回答
展开全部
这个要用2个文件,一个是在页面中设置GridView,如:<PagerTemplate>
<table width="100%">
<tr>
<td style="text-align:center">
当前 <asp:Label ID="Lb_cur" runat="server" Text ="<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>">
</asp:Label><span style="font-size: 12pt"> / </span>共 <asp:Label ID="Lb_count" runat="server" text="<%#((GridView)Container.NamingContainer).PageCount %>"></asp:Label>
页
<asp:LinkButton ID="LinkButtonFirstPage" runat="server" CommandArgument="First" CommandName="Page"
Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">首页</asp:LinkButton>
<asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev" CommandName="Page"
Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">上一页</asp:LinkButton>
点击跳转至第
<asp:TextBox ID="Tb_page" runat="server" Width="40px" Height="15px"></asp:TextBox>
页
<asp:LinkButton ID="btnGo" runat="server" causesvalidation="False"
commandargument="btnGO" commandname="Page" OnClick="btnGo_Click" text="跳转" />
<asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page"
Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">下一页</asp:LinkButton>
<asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page"
Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">尾页</asp:LinkButton>
</td>
</tr>
</table>
</PagerTemplate>
还要再CS代码里设置GridViewRow pagerRow = GridView1.BottomPagerRow;
System.Web.UI.WebControls.TextBox Tb = (System.Web.UI.WebControls.TextBox)pagerRow.Cells[0].FindControl("Tb_page");
int iflag = GridView1.PageIndex;
if (Session["page"]!=null)
{
Session.Remove("page");
}
Session["page"] = GridView1.PageIndex;
if (Tb.Text != "")
{
int page = Convert.ToInt32(Tb.Text);
if (page < 1 || page > GridView1.PageCount)
{
page = 1;
}
GridView1.PageIndex = page - 1;
}
else
{
GridView1.PageIndex = iflag;
}
ret();
ret();是绑定数据的方法
<table width="100%">
<tr>
<td style="text-align:center">
当前 <asp:Label ID="Lb_cur" runat="server" Text ="<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>">
</asp:Label><span style="font-size: 12pt"> / </span>共 <asp:Label ID="Lb_count" runat="server" text="<%#((GridView)Container.NamingContainer).PageCount %>"></asp:Label>
页
<asp:LinkButton ID="LinkButtonFirstPage" runat="server" CommandArgument="First" CommandName="Page"
Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">首页</asp:LinkButton>
<asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev" CommandName="Page"
Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">上一页</asp:LinkButton>
点击跳转至第
<asp:TextBox ID="Tb_page" runat="server" Width="40px" Height="15px"></asp:TextBox>
页
<asp:LinkButton ID="btnGo" runat="server" causesvalidation="False"
commandargument="btnGO" commandname="Page" OnClick="btnGo_Click" text="跳转" />
<asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page"
Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">下一页</asp:LinkButton>
<asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page"
Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">尾页</asp:LinkButton>
</td>
</tr>
</table>
</PagerTemplate>
还要再CS代码里设置GridViewRow pagerRow = GridView1.BottomPagerRow;
System.Web.UI.WebControls.TextBox Tb = (System.Web.UI.WebControls.TextBox)pagerRow.Cells[0].FindControl("Tb_page");
int iflag = GridView1.PageIndex;
if (Session["page"]!=null)
{
Session.Remove("page");
}
Session["page"] = GridView1.PageIndex;
if (Tb.Text != "")
{
int page = Convert.ToInt32(Tb.Text);
if (page < 1 || page > GridView1.PageCount)
{
page = 1;
}
GridView1.PageIndex = page - 1;
}
else
{
GridView1.PageIndex = iflag;
}
ret();
ret();是绑定数据的方法
展开全部
分页控制显示的行数:<asp:GridView ID="GridView1" runat="server" PageSize="20" ......> “PageSize="20"”就是显示20行
不要显示1234:<asp:GridView>与</asp:GridView>之间加<PagerSettings Visible="false" />
不要显示1234:<asp:GridView>与</asp:GridView>之间加<PagerSettings Visible="false" />
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
分页控制显示的行数:<asp:GridView
ID="GridView1"
runat="server"
PageSize="20"
......>
“PageSize="20"”就是显示20行
不要显示1234:<asp:GridView>与</asp:GridView>之间加<PagerSettings
Visible="false"
/>
ID="GridView1"
runat="server"
PageSize="20"
......>
“PageSize="20"”就是显示20行
不要显示1234:<asp:GridView>与</asp:GridView>之间加<PagerSettings
Visible="false"
/>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<asp:GridView ID="GridView1runat="server">
在gridview里面加下面标签
<PagerSettings FirstPageText="第一页" LastPageText="最后页" Mode="NextPreviousFirstLast" NextPageText="下一页" Position="Bottom" PreviousPageText="上一页" />
在gridview里面加下面标签
<PagerSettings FirstPageText="第一页" LastPageText="最后页" Mode="NextPreviousFirstLast" NextPageText="下一页" Position="Bottom" PreviousPageText="上一页" />
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
有啊,你改成显示首页上一页下一页就完了啊,而且自动分页后,显示行数是可以设置的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询