Data only displays from Page_Load??

6 posts, 0 answers
  1. Rob Ainscough
    Rob Ainscough avatar
    243 posts
    Member since:
    Jan 2010

    Posted 19 Oct 2018 Link to this post

    I have a RadGrid that becomes "visible" after a user clicks a button.  List of objects are assigned to the grid.  However the grid is showing nothing (I see only the grid border), not even the headers or anything and the DataBinding event is NOT triggered.  I've verified all the DataField names match up correctly to the List of Object properities … all good.

    As an experiment, I moved the exact same code into my Page_Load event and it populates the grid as expected??

    Do RadGrids ONLY work from Page_Load?

    Baffled,

    Any suggestions?

     

     

  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    4494 posts

    Posted 19 Oct 2018 Link to this post

    Hi Rob,

    If you are providing a data source to the grid in the code-behind, the best place to do that is its NeedDataSource event handler. The following article can be a good starting point: https://www.telerik.com/support/kb/aspnet-ajax/grid/details/how-to-bind-radgrid-properly-on-server-side.


    Regards,
    Marin Bratanov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Rob Ainscough
    Rob Ainscough avatar
    243 posts
    Member since:
    Jan 2010

    Posted 19 Oct 2018 in reply to Marin Bratanov Link to this post

    Marin,

    So you're saying it's "by design" that the Grid's datasource will not update in any event other than Page_Load?  That doesn't sound right?

    Rob.

  4. Rob Ainscough
    Rob Ainscough avatar
    243 posts
    Member since:
    Jan 2010

    Posted 19 Oct 2018 in reply to Marin Bratanov Link to this post

    Ok, the magic word I was looking for is apparently .Rebind().  So that issue is solved, but for some strange reason my RadRadioButton (GridTemplateColumn) is not firing the "OnCheckedChanged" event?

    Any hints?

    Rob.

     

  5. Rob Ainscough
    Rob Ainscough avatar
    243 posts
    Member since:
    Jan 2010

    Posted 19 Oct 2018 Link to this post

    Ignore, I had a Password validation field (RadTextBox) that got reset after the Grid.Rebind so it was blocking events until validation was cleared.

    Thanks for the help.

    Rob.

  6. Marin Bratanov
    Admin
    Marin Bratanov avatar
    4494 posts

    Posted 22 Oct 2018 Link to this post

    It's good to hear you have resolved this, Rob.
    To add a some info on the grid events - while you could provide a data source to it in other events (including postback events such as button.Click), then callings its .DataBind() or .Rebind() method would likely bind the grid to that data, this is not what we recommend, because the rich feature set of the grid may require that it is provided with data in other cases/events too, and if this is not done, such simple data binding will fail. This is why we created the NeedDataSource event, so it can serve as a single place where you provide the same data to the grid every time without worrying for the page lifecycle.
    --Marin
Back to Top