DetailTableDataBind doesn't load detail table

11 posts, 0 answers
  1. Barry Burton
    Barry Burton avatar
    25 posts
    Member since:
    Jan 2010

    Posted 08 Jan 2012 Link to this post

    I'm having an issue getting my detail table to load properly using NeedDataSource and DetailTableDataBind events.  The main grid loads as expected after the NeedDataSource event, however after clicking to expand the row, the detail table does NOT load after the DetailTableDataBind event.  Stepping through the code shows the DetailTableDataBind does fire and the DataSource is assigned.  If I use a SqlDataSource instead of during the DetailTableDataBind event, the table loads properly.  The "GetDetailView" (see below) uses the exact same stored procedure as the SqlDataSource, returning a DataTable.  Stepping through the code, the DataTable is populated with the same data as that returned using SqlDataSource. 

    The events fire properly and the DataSource is assigned a valid DataTable value at the correct moment, therefore I don't understand why the detail table does not load.  Any help in resolving the this issue will be greatly appreciated!

    protected void MyGrid_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
    {
        try
        {
             GridDataItem dataItem = e.DetailTableView.ParentItem as GridDataItem;

             int                  id            = (int) dataItem.GetDataKeyValue("Id");

             e.DetailTableView.DataSource = MyClass.GetDetailView(id);
        }
        catch(Exception ex)
        {
             // log error
        }        
    }

    protected void MyGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        try
        {
             if(e.IsFromDetailTable == false)
             {
                 MyGrid.DataSource = MyClass.GetView();
             }
        }
        catch(Exception ex)
        {
             // log error
        }
    }
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 08 Jan 2012 Link to this post

    Hello Barry,

    Here is the sample code.
    C#:
    protected void RadGrid2_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
    {
      if (e.DetailTableView.Name == "DetailTable1")
      {
         GridTableView detailtabl1 = (GridTableView)e.DetailTableView;
         GridDataItem parentItem = (GridDataItem)detailtabl1.ParentItem;
         string customerId = parentItem.GetDataKeyValue("CustomerID").ToString();
      }
    }

    -Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Barry Burton
    Barry Burton avatar
    25 posts
    Member since:
    Jan 2010

    Posted 09 Jan 2012 Link to this post

    I'm sorry, but that does nothing to answer my question.  Your code only provides a way get the customer Id,
    which I was already doing correctly anyway.  THE FOLLOWING IS THE LINE THAT IS CAUSING ME ISSUES:

    e.DetailTableView.DataSource = MyClass.GetDetailView(customerId);

    It doesn't work...the detail table is not popluated with data.  That is what I need help with.


    protected
    void RadGrid2_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
    {
      if (e.DetailTableView.Name == "DetailTable1")
      {
         GridTableView detailtabl1 = (GridTableView)e.DetailTableView;
         GridDataItem parentItem = (GridDataItem)detailtabl1.ParentItem;
         string customerId = parentItem.GetDataKeyValue("CustomerID").ToString();


           e.DetailTableView.DataSource = MyClass.GetDetailView(customerId);

      }
    }

  5. Barry Burton
    Barry Burton avatar
    25 posts
    Member since:
    Jan 2010

    Posted 09 Jan 2012 Link to this post

    Ok, here is the problem, if ParentTableRelation is declared, the DataSource does not load the detail table with data.  Remove the declaration and it does.  Should I put in a bug report on this?


    <
    ParentTableRelation>

         <telerik:GridRelationFields DetailKeyField="ChildId" MasterKeyField="ParentId" />

     </ParentTableRelation>

     

  6. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 09 Jan 2012 Link to this post

    Hello Barry,

    Check the following demo which explains programmatically binding the RadGrid.
    Grid / Programmatic Binding

    -Shinu.
  7. Barry Burton
    Barry Burton avatar
    25 posts
    Member since:
    Jan 2010

    Posted 10 Jan 2012 Link to this post

    That doesn't say one word about ParentTableRelation.  It is required under certain circumstances, but I see nowhere in any of your documentation where it states NOT to declare it when subscribing to NeedDataSource or DetailTableDataBind events.

     

  8. Tsvetina
    Admin
    Tsvetina avatar
    1873 posts

    Posted 11 Jan 2012 Link to this post

    Hi Barry,

    Both articles for binding a hierarchical grid list the exact set of steps needed to take in order to create/bind a RadGrid hierarchy. The one about using the DetailTableDataBind event does not mention using declarative relations (ParentTableRelation), since as their name suggests, they are used in cases of declarative binding only.

    http://www.telerik.com/help/aspnet-ajax/grid-hierarchical-data-binding-using-declarative-relations.html
    http://www.telerik.com/help/aspnet-ajax/grid-hierarchical-data-binding-using-detailtabledatabind.html

    However, if this did not get clear to you from the provided information in the articles, this means it could happen to others too, so we will add a note for clarity. Thank you for your feedback on this.

    Kind regards,
    Tsvetina
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  9. jen
    jen avatar
    63 posts
    Member since:
    Jun 2009

    Posted 20 Feb 2015 Link to this post

    Did you ever get this issue sorted out? I am facing the exact same problem, following the same demos, and after i set the datasource with results nothing displays. I am at my wit's end here!
  10. Barry Burton
    Barry Burton avatar
    25 posts
    Member since:
    Jan 2010

    Posted 21 Feb 2015 in reply to jen Link to this post

    Hi Jen,

    Wow, after reading this post, I see that I was incredibly hard on Telerik support, even rude...SORRY GUYS, you ARE the best in the business, I MEAN that!!!

    Jen, its been three years since my original post and yes, I did get everything working.  Why MY mistake was, I don't remember.  If you want to post your code, I will see what I can do to help.
  11. Jaume
    Jaume avatar
    1 posts
    Member since:
    Sep 2016

    Posted 30 Sep in reply to jen Link to this post

    Same problem, now solved.This worked for me: "Ok, here is the problem, if ParentTableRelation is declared, the
    DataSource does not load the detail table with data.  Remove the
    declaration and it does."
  12. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 05 Oct Link to this post

    Hello Jaume,

    Yes, you are correct. This is also mentioned in our docs:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/hierarchical-grid-types-and-load-modes/hierarchical-data-binding-using-detailtabledatabind-event#using-detailtabledatabind

    "When binding RadGrid in DetailTableDataBind, you must not use declarative relations (ParentTableRelations) in markup."

    Thank you for sharing your experience with our community.

    Regards,
    Eyup
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017