This is a migrated thread and some comments may be shown as answers.

Rebind not working Only after explicit null value for the datasource

6 Answers 284 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rasin Vadim
Top achievements
Rank 1
Rasin Vadim asked on 19 Jun 2009, 10:25 PM
Greetings to telerik team and to all the telerik community.

I've just noticed that rebinding the grid using the command RadGrid.Rebind() Doesn't fires the NeedDataSource event.
Only after adding the row:

 

this.RadGrid.DataSource = null;

 

before the
RadGrid.Rebind() everything is working properly.

Am i missing something out?

Please advice.
Thanks,
Vadim Rasin.

6 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 24 Jun 2009, 02:27 PM
Hi Rasin,

Could you, please, see how do you define RadGrid's NeedDataSource event handler and if it is properly attached to the event. Also make sure RadGrid's data source is specified only inside the NeedDataSource event.

Regards,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Jeremy
Top achievements
Rank 1
answered on 18 May 2011, 09:07 AM
Any development on this? I had the same problem and resolved it by adding datasource = null;
0
Veli
Telerik team
answered on 20 May 2011, 12:36 PM
This issue is often caused by preliminary rebinding of RadGrid. In a usual page life cycle, RadGrid does not need to rebind on every postback. It rebinds only when there are explicit Rebind() commands or some other grid command is triggered that requires an implicit rebind. Data-related commands all require rebinding - page, sort, filter, edit, update, insert, delete would all have RadGrid rebind automatically. Now, the issue you guys are getting is often caused by the fact that RadGrid is rebound once before you try to rebind it. When RadGrid is rebound more than once in the same page life cycle, it does not fire the NeedDataSource event more than once, because after the first NeedDataSource event, it has already received a DataSource. Each successive rebind after that would use this assigned data source. Successive calls to the NeedDataSource event will be skipped.

The workaround you are using simply removes the assigned DataSource from RadGrid. Thus, RadGrid is explicitly forced to call its NeedDataSource event, as it does not have any data to bind to. The more appropriate cause of this issue to search for, I believe, would be whether RadGrid rebinds before the point in which you need to rebind it. And, more importantly, how can we skip this double rebinding and return RadGrid back to its normal control life cycle, where it rebinds only when needed and certainly a single time in a page cycle.

Greetings,
Veli
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Jeremy
Top achievements
Rank 1
answered on 23 May 2011, 05:12 AM
That makes sense. I am circling through and rebinding it twice sometimes as I have the grid in a usercontrol that has dependencies on another user control. I think I'll keep resetting the datasource rather than try to refactor the spaghetti logic :)
0
William
Top achievements
Rank 1
answered on 26 Jul 2011, 06:39 AM
Hi,

I am experiencing this issue in the following scenario:-

  • NeedDatasource event is subscribed to and only place that grid DataSource is set
  • Grid ViewStateMode is disabled
  • Delete Command item in grid

Now when the user clicks the delete command the following happens (as it should):-

  1. RadGrid NeedDatasource Event fires
  2. RadGrid DeleteCommand event fires

However, the issue I have is that I want to rebind after deleting, so have to set datasource = null before rebinding to force the rebind. Is there some way of stopping the two trips to the database in this scenario? (one due to page load NeedDataSource and two for the rebind on delete command). Basically, I just want to rebind the grid after the delete command.

Thanks,

Will

0
Iana Tsolova
Telerik team
answered on 29 Jul 2011, 04:55 AM
Hello William,

If you want to avoid the NeedDataSource fired before the delete command, you need to enable the grid ViewState. More information on the grid life cycle is available below:
http://www.telerik.com/help/aspnet-ajax/grid-event-sequence.html

To prevent the implicit rebind after the delete command: You can handle the DeleteCommand/ItemCommand event and cancel it. However if you want the grid to be refreshed after the deletion, the you still should rebind it. Therefore I suggest that you manage its DataSource property entirely in the NeedDataSource event and assign to the desired value based on different conditions.

All the best,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Rasin Vadim
Top achievements
Rank 1
Answers by
Veli
Telerik team
Jeremy
Top achievements
Rank 1
William
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or