Rebind not working Only after explicit null value for the datasource

7 posts, 0 answers
  1. Rasin Vadim
    Rasin Vadim avatar
    22 posts
    Member since:
    Dec 2006

    Posted 19 Jun 2009 Link to this post

    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.
  2. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 24 Jun 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jeremy
    Jeremy avatar
    96 posts
    Member since:
    Mar 2010

    Posted 18 May 2011 Link to this post

    Any development on this? I had the same problem and resolved it by adding datasource = null;
  5. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 20 May 2011 Link to this post

    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.

  6. Jeremy
    Jeremy avatar
    96 posts
    Member since:
    Mar 2010

    Posted 23 May 2011 Link to this post

    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 :)
  7. William
    William avatar
    1 posts
    Member since:
    Jul 2011

    Posted 26 Jul 2011 Link to this post

    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

  8. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 28 Jul 2011 Link to this post

    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.

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017