Tutorial :telerik radgrid datasource null after postback



Question:

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.


Solution:1

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.


Solution:2

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;  }  


Solution:3

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.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »