1

私はグリッドビューを持っており、ページングのために特定のページ付けスタイルが必要です。ここに私が必要とする出力があります。これを達成する方法を教えてください: グリッドビューのカスタム ページネーション デザイン

4

2 に答える 2

0

PagerPosition Enumeration - TopAndBottom

このプロパティは両方でページャーを表示しますTop and Bottom

MARK UP

<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 Behind

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);
    }
}

参照

于 2012-05-08T18:00:45.583 に答える
0

GridView プロパティ内には、PaggerSettings と呼ばれるものがあります。この中には、FirstPageImageUrl、LastPageImageUrl などがあります。このフィールドには、必要なコーナーと背景を含む画像を配置する必要があります。

于 2012-05-08T17:33:52.957 に答える