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
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.
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.
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):-
- RadGrid NeedDatasource Event fires
- 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
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.