RadGrid does not display on first page load but does on postback

5 posts, 0 answers
  1. Mark Bourland
    Mark Bourland avatar
    7 posts
    Member since:
    Jan 2007

    Posted 17 Mar 2010 Link to this post

    Hello,

    I have a page with a drop-down. Based on the selection in the drop-down, data gets loaded and populates a RadGrid. I am using a custom user control for the EditTemplate, so I can't use radGrid.DataBind(). Instead, I have to use radGrid.MasterTableView.Rebind() in association with a NeedDataSource event handler.

    My problem is that when I load the page initially, I populate the drop-down and automatically select a value (first item in the list) which triggers the databinding on the RadGrid. I can step through the code in debug mode and see that the grid is being populated with data (both when the DataSource is being set and when a derived property is visited when it's displayed as a column in the grid), but when the page displays, the grid doesn't get rendered. I can then manually choose an item from the drop-down, which triggers the same grid databinding code, it displays properly the second time.

    How do I get it to display the grid the first time the page loads?

  2. Mark Bourland
    Mark Bourland avatar
    7 posts
    Member since:
    Jan 2007

    Posted 17 Mar 2010 Link to this post

    Additional info:

    When debugging, I have noticed that the grid does get bound to the data correctly.  However, it is acting like the HTML output for the grid is not rendered until AFTER the page HTML has been sent to the browser.  Here is a simplified page lifecycle that I'm seeing:

    Page_Load()
    LoadData()
    GridNeedDataSource()
    <page is rendered to the browser without the grid>

    <cause any kind of postback>
    GridNeedDataSource()
    <page is renderd to the browser WITH the grid>

    I changed EnableViewState to false and the grid displays all the time, however I've lost almost all functionality within my edit template's custom user control, which is not acceptable.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mark Bourland
    Mark Bourland avatar
    7 posts
    Member since:
    Jan 2007

    Posted 17 Mar 2010 Link to this post

    Yet more info:

    From what I can tell, the view state is being modified after the page HTML is rendered and therefore, the grid is not being displayed until the first post back happens.

    Why would disabling the viewstate on the grid (but not the page) cause the grid to properly display the first time the page is loaded?
    Why would enabling the viewstate on the grid cause the grid to NOT properly display the first time the page is loaded?
    How can I keep the benefits of having the viewstate enabled, but also display the grid on the first page load?
  5. Mark Bourland
    Mark Bourland avatar
    7 posts
    Member since:
    Jan 2007

    Posted 17 Mar 2010 Link to this post

    I can't answer WHY it was happening, but the solution that works for me is to bind the grid to an ObjectDataSource.

    <asp:ObjectDataSource ID="gridData" runat="server"/> 
    

    I was already binding the grid to a property on the page which was a collection of type List:


    protected
    List<EquipmentGridItem> GridItems { get; set; } 

    In order to use the ObjectDataSource, I created a wrapper method to return the list.


    public
    object GetGridData()  {      return GridItems;  } 

    Then I bound the grid to the object data source.


    protected
    override void OnInit(EventArgs e)  {      base.OnInit(e);        grdUnits.DataSourceID = "gridData";      gridData.TypeName = typeof (ReservationEdit).ToString();      gridData.SelectMethod = "GetGridData";  } 

    Kind of a convoluted solution, but it works.

  6. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 18 Apr 2012 Link to this post

    Think I got a similar problem. Mine was solved using the 
    RadGrid1_NeedDataSource

    Setting RadGrid1.DataSource to an array of object gave grid problems. A collapse/expand column was showed on the first page. navigating to 2nd page worked fine, back to the first gave drawing errors and the prev page + first page where highlighted below...  weird.

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