totals at the top of a DataGrid?

G

Gary

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
 
T

TJoker .NET

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.
 
Y

Yan-Hong Huang[MSFT]

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.
 
G

Gary

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

Yan-Hong Huang[MSFT]

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top