Subtotals in Gridview

H

Hutty

I have searched the net but have been unable to find a solution to
subtotaling in a gridview. I have a gridview that is bounded to sqldatasource
where I would like to subtotal rows throughout the gridview based on column
value "Type". I am using VB.NET. Thanks.
 
E

Eliyahu Goldin

The way to do this sort of things is to use a repeater or a listview with
ItemTemplate made out of two html table rows. The first <tr> will be used as
a regular row. The second <tr> will contain subtotals. It will be hidden for
all items (rows) but the last item for each Type. You will need to handle
either ItemDataBound or PreRender event to calculate the subtotals, detect
the last item for every Type and show the subtotal <tr> for the detected
last items.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 
H

Hutty

I failed to mention I am using a nested gridview in application. The second
gridview shows the details of the master gridview where I want to display
totals. My goal is to show hierarchial data with subtotals at major
intervals. Will the repeater accomplish this task? Thanks.
--
Hutty


Eliyahu Goldin said:
The way to do this sort of things is to use a repeater or a listview with
ItemTemplate made out of two html table rows. The first <tr> will be used as
a regular row. The second <tr> will contain subtotals. It will be hidden for
all items (rows) but the last item for each Type. You will need to handle
either ItemDataBound or PreRender event to calculate the subtotals, detect
the last item for every Type and show the subtotal <tr> for the detected
last items.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Hutty said:
I have searched the net but have been unable to find a solution to
subtotaling in a gridview. I have a gridview that is bounded to
sqldatasource
where I would like to subtotal rows throughout the gridview based on
column
value "Type". I am using VB.NET. Thanks.
 
R

rajiv gandhir

I have searched the net but have been unable to find a solution to
subtotaling in a gridview. I have a gridview that is bounded to sqldatasource
where I would like to subtotal rows throughout the gridview based on column
value "Type".
I am using VB.NET.

Regards
RAJIV



Hutt wrote:

Subtotals in Gridview
22-Jul-08

I have searched the net but have been unable to find a solution to
subtotaling in a gridview. I have a gridview that is bounded to sqldatasource
where I would like to subtotal rows throughout the gridview based on column
value "Type". I am using VB.NET. Thanks
--
Hutty

Previous Posts In This Thread:

Subtotals in Gridview
I have searched the net but have been unable to find a solution to
subtotaling in a gridview. I have a gridview that is bounded to sqldatasource
where I would like to subtotal rows throughout the gridview based on column
value "Type". I am using VB.NET. Thanks
--
Hutty

The way to do this sort of things is to use a repeater or a listview with
The way to do this sort of things is to use a repeater or a listview with
ItemTemplate made out of two html table rows. The first <tr> will be used as
a regular row. The second <tr> will contain subtotals. It will be hidden for
all items (rows) but the last item for each Type. You will need to handle
either ItemDataBound or PreRender event to calculate the subtotals, detect
the last item for every Type and show the subtotal <tr> for the detected
last items

--
Eliyahu Goldin
Software Develope
Microsoft MVP [ASP.NET
http://msmvps.com/blogs/egoldi
http://usableasp.ne


I failed to mention I am using a nested gridview in application.
I failed to mention I am using a nested gridview in application. The second
gridview shows the details of the master gridview where I want to display
totals. My goal is to show hierarchial data with subtotals at major
intervals. Will the repeater accomplish this task? Thanks
--
Hutt

:


Submitted via EggHeadCafe - Software Developer Portal of Choice
WPF Reflection Effect
http://www.eggheadcafe.com/tutorial...-beab-49bd76e20b9b/wpf-reflection-effect.aspx
 
G

Gregory A. Beamer

I have searched the net but have been unable to find a solution to
subtotaling in a gridview. I have a gridview that is bounded to
sqldatasource
where I would like to subtotal rows throughout the gridview based on
column
value "Type".
I am using VB.NET.

You have two choices in ASP.NET (actually any .NET)

1. Filter the results prior to binding. This means calculating subtotals and
making them a new field before you bind
2. Intercepting the binding event and adding the subtotals.

Either will work. I prefer the first if it is every row. And you have two
choices on that one:

1. Refactor the query to add subtotal (if per row subtotal is the goal this
works well)
2. Refactor the data object to add subtotal

On the second point, you can add a column to a DataSet (if used) or have the
object with a subtotal field that is automatically calculated by the "domain
model" data object.

If none of this makes sense, you need to google the basics of domain
modeling or DataSets, and possibly the binding events in the Grid you are
using.

--
Peace and Grace,
Greg

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

************************************************
| Think outside the box! |
************************************************
 

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

Forum statistics

Threads
474,085
Messages
2,570,597
Members
47,220
Latest member
AugustinaJ

Latest Threads

Top