General discussion


Include totals with numeric values via DataGrid

By MaryWeilage Editor ·
This week's .NET e-newsletter describes how to include totals with numeric values via DataGrid. Do you plan on using the tips described in this column? Is DataGrid already a part of your development toolbox? If so, what are some of your favorite uses of DataGrid? Tell us whether you use DataGrid.

If you aren't subscribed to the free .NET e-newsletter, you can automatically subscribe to it by pasting the following URL into your browser: &subs_channel=bldr_front_door&list_id=e605&tag=fb

* Please delete any extra spaces that appear when you paste this URL into your browser.

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

SQL Sum and SqlDataReader.NextResult()

by ctzn99 In reply to Include totals with numer ...

In this simple scenario I would prefer to have the database total the sum. However, instead of going back to the database with another select statement you can simply issue two select statements at the same time. Something like:

string sql = @"
select * from myTable
select sum(freight) as freight from myTable
cmd.CommandText = sql;
SqlDataReader myReader = cmd.ExecuteReader();

Your sqlDataReader object will then hold two result sets, you can bind the first result set to the datagrid then use the something like

double freight = Convert.ToDouble(reader["Freight"]);
// assign "total" to column in footer

to assign the total. One trip to the database and you can keep using the datareader. Although you'll still have to resort to the dataset if you want to use the paging.

Collapse -


by indiasbelly In reply to Include totals with numer ...

Since you didn't explain the "onfiltered" event handler, I'm assuming it's common knowledge. But I've never used it, and when I tried to look it up, I didn't find it in MSDN or VS.NET reference. I Googled it, but only found code snippets, no explanation of when and why the event fires.

From reading your code, it appears as though it fires for each item added to the DataGrid. I'd like to know more about it though. Can you provide a resource (link, short explanation) that will help?


Collapse -

onfiltered? what is this

by saden_paki In reply to onfiltered?

The code provided here is quite buggy... also there is nothing like onfiltered in datagrid, thats why the event associated with this will never be called... in order to run this I just replaced the onfiltered with OnItemDataBound and off I go... I hope I am clear what I am trying to tell.

Back to Web Development Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums