0

在 PagerSettings 内的 ASP.Net Gridview 属性中,我们如何添加名为的新模式

NumericNextPreviousFirstLast

这将显示分页为

上一页 1 2 3 下一页 末页?

4

2 回答 2

1

您无法添加新模式。

结帐http://patpack.blogspot.de/2007/04/numeric-first-last-with-next-previous.html例如

于 2012-08-23T07:46:49.250 回答
1

这可能是更好的选择。

public class CustomGrid : System.Web.UI.WebControls.GridView
{
    protected override void OnRowCreated(GridViewRowEventArgs e)
    {
        base.OnRowCreated(e);

        if (PagerSettings.Mode == PagerButtons.NumericFirstLast && e.Row.RowType == DataControlRowType.Pager)
        {
            Table pagerTable = (Table)e.Row.Cells[0].Controls[0];
            TableRow row = pagerTable.Rows[0];
            if (row.Cells.Count > 1)
            {
                if (PageIndex != 0)
                {
                    TableCell cell = new TableCell();
                    LiteralControl prev = new LiteralControl();

                    prev.Text = "<a href=\"javascript:__doPostBack('" + ClientID.Replace("_", "$") + "','Page$Prev')\">&lt;</a>";

                    cell.Controls.Add(prev);

                    if ((row.Cells[0].Controls[0] as LinkButton).CommandArgument != "First")
                    {
                        row.Cells.AddAt(0, cell);
                    }
                    else
                    {
                        row.Cells.AddAt(1, cell);
                    }
                }
                if (PageIndex != PageCount - 1)
                {
                    TableCell cell = new TableCell();
                    LiteralControl next = new LiteralControl();

                    next.Text = "<a href=\"javascript:__doPostBack('" + ClientID.Replace("_", "$") + "','Page$Next')\">&gt;</a>";

                    cell.Controls.Add(next);

                    if ((row.Cells[row.Cells.Count - 1].Controls[0] as LinkButton).CommandArgument != "Last")
                    {
                        row.Cells.Add(cell);
                    }
                    else
                    {
                        row.Cells.AddAt(row.Cells.Count - 1, cell);
                    }
                }
            }
        }
    }
}
于 2015-02-24T11:07:06.150 回答