subheaders with totals for each

G

Guest

I'm using a gridview and I have it formatted using sub headings. now I need
to get totals for each sub heading. Is this possible?

example:

BMW (sub heading) 25,000
14,252
25,000
total: 64,252

Lexus 72,633
11,500
6500
total: 90,633

and so on, is this possible to do and if so can someone point me to a site
or code snippet? I already have the subheaders I just need to figure out how
to add the totals in there as well
 
S

Steven Cheng[MSFT]

Hello Mike,

As for displaying sub total row, there does exists some article demonstrate
on adding sum total footer in GridView or datagrid:

#CodeSnip: How to Display Sum Total in the Footer of the GridView Control
http://aspalliance.com/782_CodeSnip_How_to_Display_Sum_Total_in_the_Footer_o
f_the_GridView_Control

For your scenario, you're wantting to add a sum total for each sub group in
the GridView, I think it is certainly doable and will be much easier than
displaying the grouped sales total datas in your another thread :).

I'm wondering how are you displaying the sub group in the GridView
currently? Are you using nested Databound control (such as GridView nest
Gridview or Repeater nest GridView ...)? Would you also give me the table
structure of the datasource?

For such scenario, I would suggest you use nested databinding, e.g.

use a repeater to display each main record and in each repeater row, use a
nested GridView to display sub records. Thus, you can use the above article
to calculate and display sum total data in sub GridView's footer.

here are some web artcles introducing how to perform nested databinding in
ASP.NET

#Nested GridViews with Skins in ASP.NET
http://www.codeproject.com/useritems/SkinSample.asp

#Nesting Repeaters with Hierarchical Data and Server-Binding
http://www.codeproject.com/aspnet/Server_Nested_Repeaters.asp

If you have anything unclear on this, please feel free to let me know.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Hi Steve,
This project and my other posting are for 2 different projects. I need
both of these actually to work.

for this one I have subheaders that has sales data and I need total for each
suber header then yeah a total in the footer for all as well.

I'm grouping the subheaders as such:
string salesMan
string preSales= " ";
int i = 0;
while (i <= dsSales.Tables[0].Rows.Count - 1)
{
salesMan= dsSales.Tables[0].Rows["SalesMan"].ToString();
if (salesMan.ToString() != preSales)
{
preSales= salesMan
DataRow shRow = dsSales.Tables[0].NewRow();
shRow["ID"] = salesMan;
shRow["SalesType"] = " ";
dsSales.Tables[0].Rows.InsertAt(shRow, i);
i += 1;
}
i += 1;
}
grdSales.DataSource = dsSales;
grdSales.DataBind();

then in the gridview rowdatabound i'm doing this:
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[1].Text.Equals(" "))
{
e.Row.Cells[0].Attributes.Add("align", "Left");
e.Row.Cells[0].ColumnSpan = 2;
e.Row.Cells[0].Font.Bold = true;
e.Row.Cells.RemoveAt(1);
e.Row.BackColor = Color.LightBlue;
}

so with this how can i add totals for each subheader/group?


the other posting is still valid, there 2 different projects
 
S

Steven Cheng[MSFT]

Hello Mike,

Thanks for your reply.

From your further description and the code snippet you provide, I can get
that you're manually modify the datatable's records and add those sub rows.
And in Gridview's RoeDataBound, you'll remove a certain table cell to
display the indent before each sub row, correct?

I think you can consider use nested databinding to display such main-sub
records(include calculating sum total footer data). Would you also post
the original TableStructure and sample data you will get from database
query? Thus, I can perform research against it and provide some more
detailed suggestion or code snippet.

Please feel free to let me know if you have any questions.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


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,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top