views:

67

answers:

3

After assigning RadGrid.DataSource to a Linq Query on postback DataSource is null. Is it possible to grab the Data used by the RadGrid to populate the grid after all filters and sorting has been applied?

Edit

The only methods available to grab the data are marked as internal. I think I'm just going to give up for now. If I find a solution later I'll post my answer here.

+2  A: 

This isn't a telerik thing. For all controls, DataSource property will always be null unless you explicitly re-assign and re-bind it on every postback.

You could use Session or Cache, or even gasp ViewState to keep the DataSource around, but I would advise against any of that. Ideally any action you perform on the grid like sorting and paging should result in another trip to the database for that information.

EDIT:
The reason for avoiding storing this kind of information in Session or Cache is because it is large, and per user. If you have unlimited memory on your server, then by all means store data sets all over the place per user in session and cache, but most of the time you want to keep your per-user memory footprint small.

Storing this information in ViewState is largely wasted because you will only ever show a small subset of rows to the customer, but give them a HUGE download via their bloated ViewState.

In the end care needs to be taken to handle paging, sorting, and filtering at the data access level so that you only retrieve the rows you want to actually show the user.

Josh
Interesting. Do you know if it's still possible to grab the data from the grid itself? (Not just the visible rows)
BuildStarted
Ideally only the visible rows are the ones you are retrieving from the database. Anything else is lost. All the data is essentially translated into just the values needed to populate the visible rows on the grid. So... you can't really retrieve strongly typed values back out unless you are using something like SqlDataSource, but even that usually rebinds the datasource on every postback.
Josh
Via the website all you see are the visible rows and nothing else (it seems) is contained on the page but telerik has some sort of caching option available. So I was hoping to get direct access to that - I did find this `this.RadGrid2.MasterTableView.Controls(0).Rows` which contains what I need so I'm going to head in that direction to see what I find, then I'll come back here...Thanks so far
BuildStarted
A: 

You have two choices, one to store the datasource object into your session. Or you can use any DataSource Control and rebind it during post back.

John Mao
+1  A: 

Telerik has a NeedDataSource event handler on their controls. Set the datasource there.

protected void radGridVesselSpecs_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
    if (this.Vessel == null)
        return;

    this.radGridVesselSpecs.DataSource = this.Vessel.Specifications;
}
Ed B
This still would force another fetch from the database. The original problem still remains that DataSource is not persisted across postbacks.
Josh
It depends on how you code your page. In the example above, this.Vessel is a property that adds to the ViewState when set and retrieves from the ViewState on get. On my Page_Load(!IsPostBack) i'm setting the property with data from the db. It's retrieved from viewstate on the postback so a new db call is not needed.
Ed B
I don't have a problem setting the datasource. I'm trying to retrieve the existing data after postback. Since I know that Telerik is caching my data I'd rather not recache it or send it to the viewstate at all...
BuildStarted