totals at the top of a DataGrid?

Discussion in 'ASP .Net' started by Gary, Feb 22, 2004.

  1. Gary

    Gary Guest

    Is there any way to get FooterText to show at the top of the grid instead of
    the bottom? We have hundreds of pages of grids that are almost always too
    tall to show on a page. Users are constantly scrolling down to the bottom
    to see the totals as soon as the page shows. I know I can crunch this out
    in code by putting a table on top of the grid and writing code to put the
    totals in the table but...

    Is there an easy way?
    Thanks,
    G
     
    Gary, Feb 22, 2004
    #1
    1. Advertising

  2. Gary

    TJoker .NET Guest

    Sure, but you would need a trick.
    Enable showing the Pager if you are not using it (AllowPaging = true). Set
    the property PagerStyle.Position to Top (or TopAndBottom if you need the
    real pager).
    Now you'll use the ItemCreated event to check if the item being creaeted is
    a Pager row (verify e.Item.ItemType ), if it is the pager, then remove the
    exisiting cells on the item and create the cells that will show the totals,
    programatically.

    It's not one of the easiest things to be done but definately feasible.

    --
    TJoker
    MVP: Paint, Notepad, Solitaire

    ****************************************

    "Gary" <> wrote in message
    news:e99rB4N%...
    > Is there any way to get FooterText to show at the top of the grid instead

    of
    > the bottom? We have hundreds of pages of grids that are almost always too
    > tall to show on a page. Users are constantly scrolling down to the bottom
    > to see the totals as soon as the page shows. I know I can crunch this out
    > in code by putting a table on top of the grid and writing code to put the
    > totals in the table but...
    >
    > Is there an easy way?
    > Thanks,
    > G
    >
    >
     
    TJoker .NET, Feb 22, 2004
    #2
    1. Advertising

  3. Hi Gary,

    Thanks for posting in the group.

    As I understand, the question is: Is there any way to add a customized row
    in the top of the datagrid to work like a summary row, right?

    Generally speaking, if we want to add a summary row in the end of the
    datagrid, we could use its ItemDataBound and change the content of its
    ListItemType.Footer. However, if we want to add it to the begining of the
    datagrid, that may need some coding.

    TJoker has provided you an method on it. :) You could try it first. I am
    not sure of your method of putting a table on top of the grid since you
    haven't introduced it much. Based on my experience, we can response to
    datagrid's PreRender to add a new row into it as the following: (is it the
    same as yours?)

    Private Sub DataGrid1_PreRender(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles DataGrid1.PreRender

    Dim dgitem As New DataGridItem(0, 0, ListItemType.Header)
    Dim mycell As New TableCell()
    mycell.ColumnSpan = 2 'Set it to the colspan that you want
    mycell.Text = "This is the top level header item spanning two columns!"
    dgitem.Cells.Add(mycell)
    DataGrid1.Controls(0).Controls.AddAt(0, dgitem)

    End Sub

    Hope that helps.

    Best regards,
    Yanhong Huang
    Microsoft Community Support

    Get Secure! ¨C www.microsoft.com/security
    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Yan-Hong Huang[MSFT], Feb 23, 2004
    #3
  4. Gary

    Gary Guest

    Thanks. I'll poke around with this idea. I think that creating a derived
    datagrid control might be the best approach.
    Gary

    "Yan-Hong Huang[MSFT]" <> wrote in message
    news:iFqt5Td%...
    > Hi Gary,
    >
    > Thanks for posting in the group.
    >
    > As I understand, the question is: Is there any way to add a customized row
    > in the top of the datagrid to work like a summary row, right?
    >
    > Generally speaking, if we want to add a summary row in the end of the
    > datagrid, we could use its ItemDataBound and change the content of its
    > ListItemType.Footer. However, if we want to add it to the begining of the
    > datagrid, that may need some coding.
    >
    > TJoker has provided you an method on it. :) You could try it first. I am
    > not sure of your method of putting a table on top of the grid since you
    > haven't introduced it much. Based on my experience, we can response to
    > datagrid's PreRender to add a new row into it as the following: (is it the
    > same as yours?)
    >
    > Private Sub DataGrid1_PreRender(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles DataGrid1.PreRender
    >
    > Dim dgitem As New DataGridItem(0, 0, ListItemType.Header)
    > Dim mycell As New TableCell()
    > mycell.ColumnSpan = 2 'Set it to the colspan that you want
    > mycell.Text = "This is the top level header item spanning two columns!"
    > dgitem.Cells.Add(mycell)
    > DataGrid1.Controls(0).Controls.AddAt(0, dgitem)
    >
    > End Sub
    >
    > Hope that helps.
    >
    > Best regards,
    > Yanhong Huang
    > Microsoft Community Support
    >
    > Get Secure! ¨C www.microsoft.com/security
    > This posting is provided "AS IS" with no warranties, and confers no

    rights.
    >
     
    Gary, Feb 23, 2004
    #4
  5. Hi Gary,

    You are welcome. :) Creating a customized control is a good idea if the
    control is supposed to be reused.

    Thanks for participating the community. Have a good day.

    Best regards,
    Yanhong Huang
    Microsoft Community Support

    Get Secure! ¨C www.microsoft.com/security
    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Yan-Hong Huang[MSFT], Feb 24, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SnVzdGlu?=

    Showing datagrid totals in the footer

    =?Utf-8?B?SnVzdGlu?=, Oct 14, 2004, in forum: ASP .Net
    Replies:
    9
    Views:
    4,625
    =?Utf-8?B?SnVzdGlu?=
    Oct 15, 2004
  2. =?Utf-8?B?Um9iZXJ0IENoYXBtYW4=?=

    Running totals in gridview (when you have many totals required)

    =?Utf-8?B?Um9iZXJ0IENoYXBtYW4=?=, Feb 15, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    875
    Alexey Smirnov
    Feb 16, 2007
  3. Gary

    totals at the TOP?

    Gary, Feb 21, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    121
    Alvin Bruney [MVP]
    Feb 22, 2004
  4. Rick Wiker

    DataGrid Totals Problem

    Rick Wiker, Apr 4, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    126
    Rick Wiker
    Apr 7, 2004
  5. Lyners

    dynamic column totals datagrid

    Lyners, Aug 23, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    128
    Lyners
    Aug 23, 2005
Loading...

Share This Page