Custom paging nav on GridView control Followup

Filed under: Programming — ej2 at 4:53 pm on Friday, January 27, 2006

This is a better and simpler way to do custom paging navigation as seen on this asp.net example:

<PagerTemplate>
      <asp:LinkButton CommandName="Page" CommandArgument="First"
        ID="LinkButton1" runat="server" Style="color: white">
        &lt;&lt;First</asp:LinkButton>
      <asp:LinkButton CommandName="Page" CommandArgument="Prev"
        ID="LinkButton2" runat="server" Style="color: white">
        &lt; Prev</asp:LinkButton>
      [Records <%= GridView1.PageIndex * GridView1.PageSize %>
        - <%= GridView1.PageIndex * GridView1.PageSize +
           GridView1.PageSize - 1 %>]
      <asp:LinkButton CommandName="Page" CommandArgument="Next"
        ID="LinkButton3" runat="server" Style="color: white">
        Next &gt;</asp:LinkButton>
      <asp:LinkButton CommandName="Page" CommandArgument="Last"
       ID="LinkButton4" runat="server" Style="color: white">
        Last &gt;&gt;</asp:LinkButton>
</PagerTemplate>

Custom paging nav on GridView control

Filed under: Programming — ej2 at 11:26 am on Friday, January 27, 2006

I am posting this mainly so I will have it to reference later….

The standard paging navigation on a GridView control is very basic. If you need/want to provide more information, like this:

Here is how you would do it:

protected void Grid_PreRender(object sender, EventArgs e)
  {
    GridView grid = (sender as GridView);

    if (grid != null)
    {
      GridViewRow pagerRow = grid.BottomPagerRow;

      if (pagerRow != null && pagerRow.Visible)
      {

        TableCell cell;
        Table pagerTable = (pagerRow.Cells[0].Controls[0] as Table);

        if(grid.PageIndex == 0)
        {
            cell = new TableCell();
            cell.Text = "<img src="disabledArrow_First.gif">";
            pagerTable.Rows[0].Cells.AddAt(0, cell);

            cell = new TableCell();
            cell.Text = "<img src="disabledArrow_Previous.gif">";
            pagerTable.Rows[0].Cells.AddAt(1, cell);
        }

        if((grid.PageIndex + 1) == grid.PageCount)
        {
            cell = new TableCell();
            cell.Text = "<img src="disabledArrow_Next.gif">";
            pagerTable.Rows[0].Cells.AddAt(2, cell);

            cell = new TableCell();
            cell.Text = "<img src="disabledArrow_Last.gif">";
            pagerTable.Rows[0].Cells.AddAt(3, cell);
        }
        cell = new TableCell();
        cell.Text = "Page " + (grid.PageIndex + 1)
          + " of " + grid.PageCount;

        pagerTable.Rows[0].Cells.AddAt(2, cell);

      }
    }
  } 

Found the information here: http://forums.asp.net/924427/ShowPost.aspx

Life ’06

Filed under: General News,Youth Ministry — ej2 at 10:27 am on Friday, January 27, 2006

I told myself I would start blogging again in the new year. And I have put it off for most of the month. Partly because I have been incredibly busy and partly because I feel this extreme amount of pressure to write something interesting for my readers… then I realize I don’t have any readers! That means I can continue to output the same level of crap that I always post! So watch for more meaningless drivel coming your way.

Tomorrow is the big Youth Quake trip. I am taking 20+ teenagers to a youth rally at SBU in Bolivar, MO. Should be an exciting day, full of crazy teenager antics and rock music.