Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Summing a column and displaying in the footer

Reply
Thread Tools

Summing a column and displaying in the footer

 
 
William Gower
Guest
Posts: n/a
 
      05-17-2004
I would like to sum a column in my dataset and have it displayed at the
bottom of the datagrid in the footer. How do I do that?


 
Reply With Quote
 
 
 
 
Alvin Bruney [MVP]
Guest
Posts: n/a
 
      05-17-2004
Assuming your datagrid is bound to a dataset, you can do this:

if(e.Item.ItemType == ListItemType.Footer)
{
//sum every column
for(int i = 0; i < e.Items.Count - 1; i++)
e.Item.Cells[i].Text = ds.Tables[0].Compute("Sum([" +
e.Item.Cells[i].HeaderText + "])",String.Empty);

roughly

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"William Gower" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I would like to sum a column in my dataset and have it displayed at the
> bottom of the datagrid in the footer. How do I do that?
>
>



 
Reply With Quote
 
 
 
 
Prodip Saha
Guest
Posts: n/a
 
      05-18-2004
Alvin,
What will be the result if Sum encounters a NULL value? I am assuming IsNull
function is not used in the SQL that populates the dataset.

Thanks,
Prodip

"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
news:(E-Mail Removed)...
> Assuming your datagrid is bound to a dataset, you can do this:
>
> if(e.Item.ItemType == ListItemType.Footer)
> {
> //sum every column
> for(int i = 0; i < e.Items.Count - 1; i++)
> e.Item.Cells[i].Text = ds.Tables[0].Compute("Sum([" +
> e.Item.Cells[i].HeaderText + "])",String.Empty);
>
> roughly
>
> --
> Regards,
> Alvin Bruney
> [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
> Got tidbits? Get it here... http://tinyurl.com/27cok
> "William Gower" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >I would like to sum a column in my dataset and have it displayed at the
> > bottom of the datagrid in the footer. How do I do that?
> >
> >

>
>



 
Reply With Quote
 
Alvin Bruney [MVP]
Guest
Posts: n/a
 
      05-18-2004
i'm not entirely sure but I believe it's gonna blow up like a weapon of mass
destruction. guard the code with a try catch block.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"Prodip Saha" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Alvin,
> What will be the result if Sum encounters a NULL value? I am assuming
> IsNull
> function is not used in the SQL that populates the dataset.
>
> Thanks,
> Prodip
>
> "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
> news:(E-Mail Removed)...
>> Assuming your datagrid is bound to a dataset, you can do this:
>>
>> if(e.Item.ItemType == ListItemType.Footer)
>> {
>> //sum every column
>> for(int i = 0; i < e.Items.Count - 1; i++)
>> e.Item.Cells[i].Text = ds.Tables[0].Compute("Sum([" +
>> e.Item.Cells[i].HeaderText + "])",String.Empty);
>>
>> roughly
>>
>> --
>> Regards,
>> Alvin Bruney
>> [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
>> Got tidbits? Get it here... http://tinyurl.com/27cok
>> "William Gower" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> >I would like to sum a column in my dataset and have it displayed at the
>> > bottom of the datagrid in the footer. How do I do that?
>> >
>> >

>>
>>

>
>



 
Reply With Quote
 
Prodip Saha
Guest
Posts: n/a
 
      05-19-2004
Thanks Alvin. I wish I could use IsNull function along with the Sum but it
is not allowed on Aggregate functions like Sum.

Prodip

"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
news:%(E-Mail Removed)...
> i'm not entirely sure but I believe it's gonna blow up like a weapon of

mass
> destruction. guard the code with a try catch block.
>
> --
> Regards,
> Alvin Bruney
> [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
> Got tidbits? Get it here... http://tinyurl.com/27cok
> "Prodip Saha" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Alvin,
> > What will be the result if Sum encounters a NULL value? I am assuming
> > IsNull
> > function is not used in the SQL that populates the dataset.
> >
> > Thanks,
> > Prodip
> >
> > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
> > news:(E-Mail Removed)...
> >> Assuming your datagrid is bound to a dataset, you can do this:
> >>
> >> if(e.Item.ItemType == ListItemType.Footer)
> >> {
> >> //sum every column
> >> for(int i = 0; i < e.Items.Count - 1; i++)
> >> e.Item.Cells[i].Text = ds.Tables[0].Compute("Sum([" +
> >> e.Item.Cells[i].HeaderText + "])",String.Empty);
> >>
> >> roughly
> >>
> >> --
> >> Regards,
> >> Alvin Bruney
> >> [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
> >> Got tidbits? Get it here... http://tinyurl.com/27cok
> >> "William Gower" <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed)...
> >> >I would like to sum a column in my dataset and have it displayed at

the
> >> > bottom of the datagrid in the footer. How do I do that?
> >> >
> >> >
> >>
> >>

> >
> >

>
>



 
Reply With Quote
 
Alvin Bruney [MVP]
Guest
Posts: n/a
 
      05-19-2004
You can,
use ISNULL(expression, replacementvalue)
as part of the expression and it will make the appropriate replacement. you
can see the msdn docs for a working example

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"Prodip Saha" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thanks Alvin. I wish I could use IsNull function along with the Sum but it
> is not allowed on Aggregate functions like Sum.
>
> Prodip
>
> "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
> news:%(E-Mail Removed)...
>> i'm not entirely sure but I believe it's gonna blow up like a weapon of

> mass
>> destruction. guard the code with a try catch block.
>>
>> --
>> Regards,
>> Alvin Bruney
>> [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
>> Got tidbits? Get it here... http://tinyurl.com/27cok
>> "Prodip Saha" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > Alvin,
>> > What will be the result if Sum encounters a NULL value? I am assuming
>> > IsNull
>> > function is not used in the SQL that populates the dataset.
>> >
>> > Thanks,
>> > Prodip
>> >
>> > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
>> > news:(E-Mail Removed)...
>> >> Assuming your datagrid is bound to a dataset, you can do this:
>> >>
>> >> if(e.Item.ItemType == ListItemType.Footer)
>> >> {
>> >> //sum every column
>> >> for(int i = 0; i < e.Items.Count - 1; i++)
>> >> e.Item.Cells[i].Text = ds.Tables[0].Compute("Sum([" +
>> >> e.Item.Cells[i].HeaderText + "])",String.Empty);
>> >>
>> >> roughly
>> >>
>> >> --
>> >> Regards,
>> >> Alvin Bruney
>> >> [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
>> >> Got tidbits? Get it here... http://tinyurl.com/27cok
>> >> "William Gower" <(E-Mail Removed)> wrote in message
>> >> news:(E-Mail Removed)...
>> >> >I would like to sum a column in my dataset and have it displayed at

> the
>> >> > bottom of the datagrid in the footer. How do I do that?
>> >> >
>> >> >
>> >>
>> >>
>> >
>> >

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Summing the values of group footer RDLC cloucas Software 2 10-19-2012 03:51 PM
Using ternary and summing array flebber C Programming 11 11-21-2011 07:39 AM
Sortable column on DataGrid -- column header not displaying Teej ASP .Net Datagrid Control 2 08-15-2006 06:23 PM
Any way to reorder how a datagrid is drawn (header/footer/items vs.header/items/footer)? Henrik ASP .Net Datagrid Control 1 07-06-2006 12:23 AM
Counting and summing elements in an array? Help! Alf P. Steinbach C++ 2 02-05-2004 09:27 AM



Advertisments