Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
asp.net中的Gridview分页样式_Asp.net_Gridview_Pagination_Styling - Fatal编程技术网

asp.net中的Gridview分页样式

asp.net中的Gridview分页样式,asp.net,gridview,pagination,styling,Asp.net,Gridview,Pagination,Styling,我有一个gridview,需要一个特定的分页样式,对于分页,这里是我需要的输出,谁能告诉我如何实现这一点: 在GridView属性中有一个称为PaggerSettings的属性。 在这个页面中有FirstPageImageUrl、LastPageImageUrl等等。 在此字段中,您应该放置带有所需角和背景的图像。PagerPosition枚举-顶部和底部 此属性将在顶部和底部显示寻呼机 加价 代码隐藏 您好@Nilish,回答得很好,这是我一直在寻找的,但我无法在顶部显示此页面,即使在设置Pa

我有一个gridview,需要一个特定的分页样式,对于分页,这里是我需要的输出,谁能告诉我如何实现这一点:

在GridView属性中有一个称为PaggerSettings的属性。 在这个页面中有FirstPageImageUrl、LastPageImageUrl等等。 在此字段中,您应该放置带有所需角和背景的图像。

PagerPosition枚举-顶部和底部 此属性将在顶部和底部显示寻呼机

加价 代码隐藏
您好@Nilish,回答得很好,这是我一直在寻找的,但我无法在顶部显示此页面,即使在设置PagerSetting Position=topandbottom后,这里的检查对我没有帮助,因为他们只是指底部位置,我希望顶部和底部都有。只需将底部替换为topandbottom似乎问题在于,在上面的代码中,该实现是针对BottomPagerRow的,因此需要显式实现TopPagerRow,不管怎样,它现在就可以工作了。。谢谢你的推荐
<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>
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);
    }
}