在asp.net gridview的分页风格 [英] Gridview paging style in asp.net
本文介绍了在asp.net gridview的分页风格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个gridview,并且需要特定的分页样式,对于寻呼,这里是输出我需要的,谁能告诉我如何才能做到这一点:
i have a gridview, and need a specific pagination style, for the Paging, here's what the output i need, can anyone tell me how can i achieve this:
推荐答案
此属性将显示在寻呼机两者的 <大骨节病>顶部和底部骨节病>
PagerPosition Enumeration - TopAndBottom
This property will display the pager at both Top and Bottom
<PagerTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
CommandName="Page" CommandArgument="First">First</asp:LinkButton>
<asp:Label ID="pmore" runat="server" Text="..."></asp:Label>
<asp:LinkButton ID="LinkButton2" runat="server"
CommandName="Page" CommandArgument="Prev">Pre</asp:LinkButton>
<asp:LinkButton ID="p0" runat="server" >LinkButton</asp:LinkButton>
<asp:LinkButton ID="p1" runat="server" >LinkButton</asp:LinkButton>
<asp:LinkButton ID="p2" runat="server" >LinkButton</asp:LinkButton>
<asp:Label ID="CurrentPage" runat="server" Text="Label"></asp:Label>
<asp:LinkButton ID="p4" runat="server" >LinkButton</asp:LinkButton>
<asp:LinkButton ID="p5" runat="server" >LinkButton</asp:LinkButton>
<asp:LinkButton ID="p6" runat="server" >LinkButton</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server"
CommandName="Page" CommandArgument="Next">Next</asp:LinkButton>
<asp:Label ID="nmore" runat="server" Text="..."></asp:Label>
<asp:LinkButton ID="LinkButton4" runat="server"
CommandName="Page" CommandArgument="Last">Last</asp:LinkButton>
</PagerTemplate>
<大骨节病> code 骨节病>
的背后protected void GridView1_DataBound(object sender, EventArgs e)
{
GridViewRow gvr = GridView1.BottomPagerRow;
Label lb1 = (Label)gvr.Cells[0].FindControl("CurrentPage");
lb1.Text = Convert.ToString(GridView1.PageIndex+1);
int[] page = new int[7];
page[0] = GridView1.PageIndex - 2;
page[1] = GridView1.PageIndex - 1;
page[2] = GridView1.PageIndex;
page[3] = GridView1.PageIndex + 1;
page[4] = GridView1.PageIndex + 2;
page[5] = GridView1.PageIndex + 3;
page[6] = GridView1.PageIndex + 4;
for (int i = 0; i < 7; i++)
{
if (i != 3)
{
if (page[i] < 1 || page[i] > GridView1.PageCount )
{
LinkButton lb = (LinkButton)gvr.Cells[0].FindControl("p" + Convert.ToString(i));
lb.Visible = false;
}
else
{
LinkButton lb = (LinkButton)gvr.Cells[0].FindControl("p" + Convert.ToString(i));
lb.Text = Convert.ToString(page[i]);
lb.CommandName = "PageNo";
lb.CommandArgument = lb.Text;
}
}
}
if (GridView1.PageIndex == 0)
{
LinkButton lb = (LinkButton)gvr.Cells[0].FindControl("LinkButton1");
lb.Visible = false;
lb = (LinkButton)gvr.Cells[0].FindControl("LinkButton2");
lb.Visible = false;
}
if (GridView1.PageIndex == GridView1.PageCount - 1)
{
LinkButton lb = (LinkButton)gvr.Cells[0].FindControl("LinkButton3");
lb.Visible = false;
lb = (LinkButton)gvr.Cells[0].FindControl("LinkButton4");
lb.Visible = false;
}
if (GridView1.PageIndex > GridView1.PageCount - 5)
{
Label lbmore = (Label)gvr.Cells[0].FindControl("nmore");
lbmore.Visible = false;
}
if (GridView1.PageIndex < 4)
{
Label lbmore = (Label)gvr.Cells[0].FindControl("pmore");
lbmore.Visible = false;
}
}
void lb_Command(object sender, CommandEventArgs e)
{
GridView1.PageIndex = Convert.ToInt32(e.CommandArgument) - 1;
}
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Pager)
{
GridViewRow gvr = e.Row;
LinkButton lb = (LinkButton)gvr.Cells[0].FindControl("p0");
lb.Command += new CommandEventHandler(lb_Command);
lb = (LinkButton)gvr.Cells[0].FindControl("p1");
lb.Command += new CommandEventHandler(lb_Command);
lb = (LinkButton)gvr.Cells[0].FindControl("p2");
lb.Command += new CommandEventHandler(lb_Command);
lb = (LinkButton)gvr.Cells[0].FindControl("p4");
lb.Command += new CommandEventHandler(lb_Command);
lb = (LinkButton)gvr.Cells[0].FindControl("p5");
lb.Command += new CommandEventHandler(lb_Command);
lb = (LinkButton)gvr.Cells[0].FindControl("p6");
lb.Command += new CommandEventHandler(lb_Command);
}
}
这篇关于在asp.net gridview的分页风格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文