Sunday, February 19, 2012

How to access underlaying DataView of SQLDataSouce in its Selected event

I need access to the underlying DataView associated with a declaratively defined SQLDataSource. Ideally, I need this access in the SQLDataSource'sSelected event. I know that I can use the SQLDataSouce.Select()method to return the underlying DataView object. But, there is a GridView control bound to the datasource so I don't want to explicity call Select() since it will end up being called again implicity by the gridview itself. I have seen that this can be done with an ObjectDataSouce as follows:

void odsDataSouce_Selected(object sender, ObjectDataSourceStatusEventArgs e) {
DataView oDV = (DataView)e.ReturnValue;
}

Is there any way to accomplish the same thing with a SQLDataSouce? It seems hard to believe that the query results are not exposed to the Selected event.

Thanks!

have a look through my posts to see how to get the underlying data table, and this all rows/columns|||

sbyard,

I saw your post about how to use a sqldatasource programmatically but that still involves using the select() method. In my situation a gridview is bound to the datasource so the select is implicit. I need access to the data in an event such as the selected event.

Thanks

|||

You cannot get to the underlying data the way that you want to. However...

By the time the selected event is raised, the grid will be populated, so you can iterate the rows and columns.

If you want to process the data BEFORE it is bound, then you wil have to create your own data table and fill this manually, process the data, then bind it. This is what we were mostly doing in ASP.NET 1.1 anyway.

|||Thanks for your help.

No comments:

Post a Comment