W
William Gower
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?
bottom of the datagrid in the footer. How do I do that?
Alvin Bruney said: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.Text = ds.Tables[0].Compute("Sum([" +
e.Item.Cells.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 said: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?
Prodip Saha said: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 said: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.Text = ds.Tables[0].Compute("Sum([" +
e.Item.Cells.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 said: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?
Alvin Bruney said: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 said: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 said: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.Text = ds.Tables[0].Compute("Sum([" +
e.Item.Cells.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
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?
Prodip Saha said: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 said: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 said: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
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.Text = ds.Tables[0].Compute("Sum([" +
e.Item.Cells.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
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?
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.