How to access the datasource of a GridView

  • Thread starter Thread starter Steven Blair
  • Start date Start date
S

Steven Blair

Hi,

I am using a GridView and have it bound to a ObjectDataSource.
After the binding has been successfull, I need to access the original
datasource (which I guess is a DataSet) to display some reporting
information.

Anyone any idea how to do this?

I think I need to grab the DataSet returned from the DataObjectMethod,
loop round it and add up the columns I need for reporting. Crude I know,
but does anyone have a better suggestion for this?

Here is ane example of what I need to display:

//Original Databound GridView

Amount Type Source
10 V S
15 V K

//Then on a seperate GridView I want a little summary report:

Total Amount
25

I don't want to go back to the Database for this information as the
query to get this information (a lot more complex than the above
example) is very expensive.

Any help / alterantives on this would be appreciated.

Regards,

Steven
 
Steven,

See inline:
I am using a GridView and have it bound to a ObjectDataSource.
After the binding has been successfull, I need to access the original
datasource (which I guess is a DataSet) to display some reporting
information.

Why would it be a dataset? ObjectDataSource instances are used to get
data from objects, not from data sets.
Anyone any idea how to do this?

You would need the data in data set format, not an object.
I think I need to grab the DataSet returned from the DataObjectMethod,
loop round it and add up the columns I need for reporting. Crude I know,
but does anyone have a better suggestion for this?

Here is ane example of what I need to display:

//Original Databound GridView

Amount Type Source
10 V S
15 V K

//Then on a seperate GridView I want a little summary report:

Total Amount
25

I don't want to go back to the Database for this information as the
query to get this information (a lot more complex than the above
example) is very expensive.

I would recommend a data set to populate this. This way, you can know
exactly what the structure of the data source is, and tally up whatever you
need to. Either that, or figure out what object you are connecting to the
grid through the object data source.

Hope this helps.
 
Steven,

Assuming that your ODS returns a DataTable:

protected void ObjectDataSourceMain_Selected(object sender,
ObjectDataSourceStatusEventArgs e)
{
// bubble exceptions before we touch e.ReturnValue
if (e.Exception != null) throw e.Exception;

// get the DataTable from the ODS select mothod
DataTable dataTable = (DataTable)e.ReturnValue;

// ...
}

You can do the same thing with a DataSet. You need to wire up the Selected
event and make sure to check for exceptions within this code as I did in the
above example.

Hope this helps,
 

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

Back
Top