This is a migrated thread and some comments may be shown as answers.

DetailTableDataBind doesn't load detail table

10 Answers 406 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Barry Burton
Top achievements
Rank 1
Barry Burton asked on 09 Jan 2012, 02:26 AM
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
    }
}

10 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 09 Jan 2012, 05:08 AM
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.
0
Barry Burton
Top achievements
Rank 1
answered on 09 Jan 2012, 08:11 PM
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);

  }
}

0
Barry Burton
Top achievements
Rank 1
answered on 09 Jan 2012, 10:58 PM
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>

 

0
Shinu
Top achievements
Rank 2
answered on 10 Jan 2012, 05:36 AM
Hello Barry,

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

-Shinu.
0
Barry Burton
Top achievements
Rank 1
answered on 10 Jan 2012, 05:11 PM
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.

 

0
Tsvetina
Telerik team
answered on 11 Jan 2012, 01:02 PM
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
0
jen
Top achievements
Rank 1
answered on 20 Feb 2015, 09:03 PM
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!
0
Barry Burton
Top achievements
Rank 1
answered on 21 Feb 2015, 04:27 PM
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.
0
Jaume
Top achievements
Rank 1
answered on 30 Sep 2016, 10:23 AM
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."
0
Eyup
Telerik team
answered on 05 Oct 2016, 05:47 AM
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.
Tags
Grid
Asked by
Barry Burton
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Barry Burton
Top achievements
Rank 1
Tsvetina
Telerik team
jen
Top achievements
Rank 1
Jaume
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or