Page view counter

DataGrid Paging - Page x of N

Last post 09-24-2004 5:38 PM by NestorLeone. 19 replies.

Sort Posts:

  • DataGrid Paging - Page x of N

    09-14-2002, 10:08 AM
    • Loading...
    • MyerK
    • Joined on 08-06-2002, 3:18 PM
    • Ft Lauderdale
    • Posts 61
    • Points 305
    This sounds like it should be pretty simple (for someone who knows how).

    In the Pager control and on the opposite side (like on this forum) from the selector I would like to include 'Page x of n'

    Thanks.
  • Re: DataGrid Paging - Page x of N

    09-14-2002, 1:31 PM
    • Loading...
    • phishstick40
    • Joined on 07-25-2002, 1:27 PM
    • NIST - Gaithersburg, MD
    • Posts 120
    • Points 600
    here are some properties of the datagrid you may find useful:

    -CurrentPageIndex
    -PageCount

    i guess you could use Items.Count / PageSize too

    i'm not at home to verify, but you may have to add 1 to CurrentPageIndex to get the page number as i believe it is a 0-based index
  • Re: DataGrid Paging - Page x of N

    09-14-2002, 1:32 PM
    • Loading...
    • Colt
    • Joined on 06-16-2002, 9:01 PM
    • Hong Kong
    • Posts 1,986
    • Points 15,569
    • ASPInsiders
      TrustedFriends-MVPs
    Hi MyerK,

    You can get the Page x of n by using:
    E.g.

    Current Page Index (x) = dgd_MemberListing.CurrentPageIndex + 1
    Total Page No. (n) = dgd_MemberListing.PageCount
    Construct them into a String called "strNewPager"

    Then, in the ItemCreat event of the DataGrid:
    E.g.
    if(e.Item.ItemType == ListItemType.Pager)
    {
    TableCell pager = (TableCell)e.Item.Controls[0];

    pager.Controls.AddAt(0,new LiteralControl(strNewPager));
    }

    The Page x of n will be display on the Pager of a DataGrid then.

    ;)

    Hope This Helps,
  • Re: DataGrid Paging - Page x of N

    09-14-2002, 4:17 PM
    • Loading...
    • MyerK
    • Joined on 08-06-2002, 3:18 PM
    • Ft Lauderdale
    • Posts 61
    • Points 305
    Thanks Colt.

    I've been using the PageCount and CurrentPageIndex but didn't know how to get a control into the Pager area.

    Now all I've got to do is muddle (translate) through your C# into VB.
  • Re: DataGrid Paging - Page x of N

    09-14-2002, 6:34 PM
    • Loading...
    • gbrown
    • Joined on 06-14-2002, 3:27 PM
    • Florida
    • Posts 67
    • Points 335
  • Re: DataGrid Paging - Page x of N

    09-15-2002, 12:23 AM
    • Loading...
    • ReyN
    • Joined on 07-28-2002, 10:53 AM
    • Pilipinas
    • Posts 413
    • Points 2,108
  • Re: DataGrid Paging - Page x of N

    09-15-2002, 7:07 AM
    • Loading...
    • MyerK
    • Joined on 08-06-2002, 3:18 PM
    • Ft Lauderdale
    • Posts 61
    • Points 305
    Thanks.

    The translators will certainly help.
  • Re: DataGrid Paging - Page x of N

    09-15-2002, 10:11 AM
    • Loading...
    • MyerK
    • Joined on 08-06-2002, 3:18 PM
    • Ft Lauderdale
    • Posts 61
    • Points 305
    Colt,

    I've gotten as far as the following.

    I don't get any errors but nothing seems to happen either. I assume something was added.

    How do I indicate the type of control I wash to add?
    How do I then place a value in the control?

    Thanks.

    '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    'The following is called on the onItemCreated event of the DataGrid
    '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

    Sub DataGrid1_ItemCreated(s as Object, e as DataGridItemEventArgs)

    If (e.Item.ItemType=ListItemType.Pager) Then
    Dim strNewPager as String
    Dim Pager as TableCell=CType(e.Item.Controls(0), TableCell)
    Pager.Controls.AddAt(0,New LiteralControl(strNewPager))
    End If
    End Sub
  • Re: DataGrid Paging - Page x of N

    09-16-2002, 12:29 AM
    • Loading...
    • guxin1999
    • Joined on 07-31-2002, 7:54 PM
    • Posts 2
    • Points 10

    you need:

    strNewPager = "Page ";

    Otherwise in your program, strNewPager is an empty string.
  • Re: DataGrid Paging - Page x of N

    09-16-2002, 2:14 AM
    • Loading...
    • ReyN
    • Joined on 07-28-2002, 10:53 AM
    • Pilipinas
    • Posts 413
    • Points 2,108
    okay

    here's a working example that is similar, but takes the topic at hand a step further, by adding custom navigation buttons. the customization, though, is done at the header row, not at the pager. this way, users can still simultaneously avail of the built-in pager.

    Using the Built-In Pager with Custom Navigation Controls

    hth :-)

    Reynald V. Nuñez
    aspxtreme
  • Re: DataGrid Paging - Page x of N

    09-16-2002, 7:15 AM
    • Loading...
    • MyerK
    • Joined on 08-06-2002, 3:18 PM
    • Ft Lauderdale
    • Posts 61
    • Points 305
    quzin1999

    Thanks.

    That placed the text "Page " in the Pager.

    However, I don't really quite understand what I did.

    Do we have any control over what type of control gets placed there?
    Also, can we adjust its location?

  • Re: DataGrid Paging - Page x of N

    09-19-2002, 9:56 AM
    Re: DataGrid Paging - Page x of N
    Yeah, my question is regarding placement also.

    I got the 'Page x of n' to go into the footer, but it places it right next to 'Prev Next.' How would I specify one to go on one side of the footer, and the other to go on the other side of the footer?

    Here is my code for the two items mentioned above:



    public void ChangePage(object sender, DataGridPageChangedEventArgs objArgs)
    {
    dgFiles.CurrentPageIndex = objArgs.NewPageIndex;

    dgFiles.DataSource = alBad;
    dgFiles.DataBind();
    }


    public void CustomPager(object sender, DataGridItemEventArgs e)
    {
    // PAGER STUFF
    int currentPage = dgFiles.CurrentPageIndex +1;
    int totalPages = dgFiles.PageCount;
    string strNewPager = "Page " + currentPage + " of "
    + totalPages;

    if(e.Item.ItemType == ListItemType.Pager)
    {
    TableCell pager = (TableCell)e.Item.Controls[0];

    pager.Controls.AddAt(0,new LiteralControl(strNewPager));
    }
    }



    Thanks,
    Craig
    -Craig

    U-Sports.net - Taking Fantasy Football to School
  • Re: DataGrid Paging - Page x of N

    09-19-2002, 10:39 PM
    • Loading...
    • ReyN
    • Joined on 07-28-2002, 10:53 AM
    • Pilipinas
    • Posts 413
    • Points 2,108
    hi Craig

    if you view the source of the generated HTML, you will see that the pager row is actually comprised of one <tr>...</tr> element with ONE <td>...</td> element whose colspan attribute is internally set to the number of columns in your grid.

    to achieve what you want, you need to split the pager into two cells, one cell (left-aligned) for your "Page x of n" text, and the other cell (right-aligned) for the pager controls. you also need to define how many columns each cell would span.

    this is how it's done in the sample i posted above, only it's done in the header row. but the logic remains.

    hth :-D

    Reynald V. Nuñez
    aspxtreme
  • Re: DataGrid Paging - Page x of N

    09-23-2002, 3:43 PM
    Ok, thanks for all your help so far. I'm starting to get it now. I've taken the header, removed the only column in it, and then added two new columns. My question now is, how do I reference the 'original' default Pager? ie. How to I make that 'standard' header go into the cell I choose? I would like it to go into the cell with the word 'test.'


    if(e.Item.ItemType == ListItemType.Pager)
    {
    TableCellCollection pager = e.Item.Cells;
    //int temp = e.Item.Cells.Count;

    pager.RemoveAt(0);

    pager.AddAt(0,new TableCell());
    pager.AddAt(1,new TableCell());

    pager[0].Text = strNewPager;
    pager[0].HorizontalAlign = HorizontalAlign.Left;

    pager[1].Text = "Test";
    }


    Thanks!,
    Craig
    -Craig

    U-Sports.net - Taking Fantasy Football to School
  • Re: DataGrid Paging - Page x of N

    09-23-2002, 5:54 PM
    • Loading...
    • ReyN
    • Joined on 07-28-2002, 10:53 AM
    • Pilipinas
    • Posts 413
    • Points 2,108
    yo Craig

    if you will be customizing the pager row itself and still use the "standard" paging controls, then you should not remove the original pager cell.

    simply add another cell for your text. something like:
    if (e.Item.ItemType == ListItemType.Pager) { 
    
    TableCellCollection pager = e.Item.Cells;
    pager.AddAt(0,new TableCell());

    // set up the inserted cell, cell 0
    pager[0].Text = strNewPager;
    pager[0].ColumnSpan = number of columns to span here;
    pager[0].HorizontalAlign = HorizontalAlign.Left;

    // set up the original cell, now cell 1
    pager[1].ColumnSpan = number of columns to span here;;
    pager[1].HorizontalAlign = HorizontalAlign.Right;
    }
    hth :)

    Reynald V. Nuñez
    aspxtreme
Page 1 of 2 (20 items) 1 2 Next >