I am trying to imitate the demo shown here:
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/nestedviewtemplate/defaultcs.aspx
However, I see that a SQLDataSource control is used to do the databinding, in particular to the Graph, as this is heart of what
I wish to replicate. Is there a way to do the same thing without using the SQL DataSource or have the control there but bind it programmatically. The online documentation says it's possible but I haven't seen any examples. If so, a code example would do me a world of good. For example, how would the SQLDataSource control be set up if it were programmatically used? How would you access this SQLDataSourceControl from code to programmatically assign the datasource the desired collection?
Thanks for you help,
Josh
16 Answers, 1 is accepted
Basic steps that you need to follow in order to create hierarchical Telerik RadGrid programmatically (having data source control for data content generation) are shown in the following help article:
Programmatic creation (Create hierarchical grid programmatically section)
Sincerely yours,
Pavlina
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.

I have the same issue in binding the NestedviewTemplate. I am facing the problem in binding the detail table which is under nested view grid.I used RadGrid1_preRender event to bind the nestedview grid. But the problem arised during i call the Nested grid's
'DetailTableDataBind' event it goes againg to 'RadGrid1_preRender' event and bind the nested grid again, so as a result i could not see the detail table data after i expanding the nested grid row.
Please guide me at what solution help to overcome this problem
-Thanks

Thanks for the response, but I'm not seeking to dynamically create the grid. In the NestedViewTemplate, I want to be able to hook up a datatable to a chart like object without using.the SQLDataSource control.
This page http://www.telerik.com/help/aspnet-ajax/grdnestedviewtemplate.html has this paragraph:
RadGrid gives you the ability to data bind the controls in a nested view template to a single item of a specified data source. You can have three modes of data binding the nested view template: ServerOnDemand, ServerBind or Client, which can be set through the HierarchyLoadMode property of the corresponding table view. To support this feature, RadGrid exposes an additional property for its table view objects called NestedViewSettings. The NestedViewSettings allow you to specify a data source object contained on the page to which the template should be bound, as well as a relation to the parent level. These two properties can be defined declaratively or programmatically through the NestedViewSettings.DataSourceID and NestedViewSettings.ParentTableRelation properties respectively. The ParentTableRelation is specified in the same way as the declarative relations for hierarchical tables.
And this is what is shown for declarative binding:
<NestedViewSettings DataSourceID="SqlDataSource2"> |
<ParentTableRelation> |
<telerik:GridRelationFields DetailKeyField="CustomerID" MasterKeyField="CustomerID" /> |
</ParentTableRelation> |
</NestedViewSettings> |
My question is how do I do this same thing without using a SQLDataSource Control? Also, is an object data source control allowed instead? Is there some kind of DataSource property which I can set rather than use a control?
Josh
RadGrid gives you the ability to data bind the controls in a nested view template to a single item of a specified data source. For further information, please review this online demo.
Additionally, I suggest you review this help article for more information about hierarchical data-binding using declarative relations:
http://www.telerik.com/help/aspnet-ajax/grdhierarchicaldatabindingusingneeddatasource.html
Kind regards,
Pavlina
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.

In what ways can you specify this data source?
Obviously it is possible to specify the DataSourceId of the NestedViewSettings. But this means you must have a DataSource declared in your aspx.
I would, in my case, much rather supply it in response to an event much like:
void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
RadGrid1.DataSource = GetHierarchicalDsFromXml();
}
But this is not possible?
In my case all data is in the dataset that I give to RadGrid1.DataSource. If I only have normal DetailTables all is fine, but when I want to use the NestedViewTemplate I get stuck.
In order to achieve your goal, I suggest that you bind both grids through the NeedDataSource event. For the outer grid there is nothing specific, you can do it as for a regular grid. And in the inner grid NeedDataSource event, you can get reference to the outer grid expanded item, e.g. the parent item. Thus you can get a data field value of the expanded item and use it for retrieving the inner grid data source.
Let me know if this helps and if further questions arise.
Sincerely yours,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

Could you please detail about data-binding the NestedView in the NeedDataSource function?
I too would like to use a NestedViewTemplate. Considering a table of Customers, I would like each row or customer to be clicked, revealing the several Orders belonging to that Customer. However, I would not want to use declarative binding, by specifying SQL Data Sources in the aspx, but to bind to DataTables in the code-behind file instead.
This works using a DetailTable and the RadGrid1_DetailTableDataBind function... But I would prefer to use the NestedView.
Thanks.
Attached to this message is a simple working project which handles the desired functionality. Please
give it a try and let me know if it works as expected.
I hope this helps.
All the best,
Pavlina
the Telerik team

Works great! Thank you very much, for the really quick response too!
The NestedViewTemplate's RadGrid, thanks to your _NeedDataSource function, gets the right orders, while the nested view is able to contain additional controls and formatting.
Again, thanks a lot!

Thanks again for the NestedView example - worked great!
I was trying to see now how it looked with a Rad Panel Bar... For the same situation as the previous one. So the panel bars items are the customers (first level), inside each item I could build an item template base on the customer's orders...
I understand we can build the entire rad panel programmatically : http://demos.telerik.com/aspnet-ajax/panelbar/examples/populatingwithdata/dynamiccreation/defaultcs.aspx
I've read this article: http://www.telerik.com/help/aspnet-ajax/panel_datadatatableview.html But the datatable describes an hierarchy of it's only elements...
Is there a way, like for the NestedView, to have the items bound to the Customer's datatable, and the item's content bound to the Orders for that customer datatable?
Thanks!
Note: Wasn't sure about creating a new thread for this subject... I hope the reply to the thread is alright :)
You can check out these online resources for more information on how to achieve your goal.
http://www.telerik.com/help/aspnet-ajax/panel_templatesbinding.html
http://demos.telerik.com/aspnet-ajax/panelbar/examples/functionality/hierarchical/defaultcs.aspx
I hope this gets you started properly.
Greetings,
Pavlina
the Telerik team

Thankyou for once again replying to my matter. I already had checked the 2nd link (the demos one), but missed the 1st, which has a lot of great info regarding the panel bar. However, I don't think I found anything to address my specific situation... Using the customers and orders items, here's the closest I've got so far:
The aspx:
<
telerik:RadPanelBar
runat
=
"server"
ID
=
"RadPanelBar1"
ExpandMode
=
"SingleExpandedItem"
DataFieldID
=
"OrderID"
DataFieldParentID
=
"CustomerID"
DataTextField
=
"OrderName"
Width
=
"600px"
>
<
ItemTemplate
>
<
fieldset
>
<
legend
>Orders</
legend
>.........Template content............
<
telerik:RadGrid
ID
=
"RadGridOrdersOfCustomer"
runat
=
"server"
OnNeedDataSource
=
"RadGridOrdersOfCustomer_NeedDataSource"
>
<
MasterTableView
AutoGenerateColumns
=
"false"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"OrderID"
UniqueName
=
"OrderID"
HeaderText
=
"OrderID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"OrderName"
UniqueName
=
"OrderName"
HeaderText
=
"OrderName"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
</
fieldset
>
</
ItemTemplate
>
</
telerik:RadPanelBar
>
and the code-behind:
private
DataTable GetCustomers()
{
DataTable table =
new
DataTable();
table.Columns.Add(
"CustomerID"
);
table.Columns.Add(
"IDParent"
);
table.Columns.Add(
"CustomerName"
);
table.Columns.Add(
"URL"
);
table.Columns.Add(
"Tooltip"
);
table.Rows.Add(
new
string
[] {
"1"
,
null
,
"Customer 1"
,
"Default.aspx"
,
"Customer 1 tooltip"
});
table.Rows.Add(
new
string
[] {
"2"
,
null
,
"Customer 2"
,
"Default.aspx"
,
"Customer 2 tooltip"
});
/*
table.Rows.Add(new string[] { "3", "1", "Order 1.1", "Default.aspx", "Order 1.1 tooltip" });
table.Rows.Add(new string[] { "4", "1", "Order 1.2", "Default.aspx", "Order 1.2 tooltip" });
table.Rows.Add(new string[] { "5", "2", "Order 2.1", "Default.aspx", "Order 2.1 tooltip" });
table.Rows.Add(new string[] { "6", "2", "Order 2.2", "Default.aspx", "Order 2.1 tooltip" });
*/
return
table;
}
private
DataTable GetOrdersForCustomer(
int
customerId)
{
DataTable dt =
new
DataTable();
dt.Columns.Add(
"OrderID"
);
dt.Columns.Add(
"OrderName"
);
DataRow
dr = dt.NewRow();
dr[0] =
"1"
;
dr[1] =
"Order 1"
;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] =
"2"
;
dr[1] =
"Order 2"
;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] =
"3"
;
dr[1] =
"Order 3"
;
dt.Rows.Add(dr);
return
dt;
}
private
void
Bind()
// called at Page_Load
{
DataTable dt = GetCustomers();
RadPanelBar1.DataSource = dt;
RadPanelBar1.DataFieldID =
"CustomerID"
;
RadPanelBar1.DataFieldParentID =
"IDParent"
;
RadPanelBar1.DataTextField =
"CustomerName"
;
RadPanelBar1.DataValueField =
"CustomerID"
;
RadPanelBar1.DataBind();
}
protected
void
RadGridOrdersOfCustomer_NeedDataSource(
object
source, GridNeedDataSourceEventArgs e)
{
DataTable dt = GetOrdersForCustomer(1);
(source
as
RadGrid).DataSource = dt;
}
I was trying to get the orders to be shown and hidden by clicking the customer title bar... (I want to bind to DataTables, and not using SqlDataSources.)
This was accomplished with the hierarchical grid view and nested view template, but I was trying it out with the panel bar...
In this case I suggest that you open a formal support ticket for the RadPanelBar control and enclose your requirements and the project you have currently. Thus our colleagues responsible for the RadPanelBar control will be able to provide a resolution for you.
Greetings,
Iana
the Telerik team

GridDataItem parentItem = ((source
as RadGrid).NamingContainer as GridNestedViewItem).ParentItem as GridDataItem;
So i am unable to find the DataKey and current row identifier. Does the nestedview grid works for this version. Do you have sample code?
I have attached the screen shot for reference.
The NestedViewTemplate should be available in the specified version of RadControls for ASp.NET AJAX. However I suggest that you try debugging your code and see what is in fact the NamingContainer of the preceding RadGrid. If the inner grid is placed directly in the NestedViewTemplate, its NamingContainer should be the GridNestedViewItem. But if the inner grid is nested in another control in the NestedViewTemplate, then you might need to get this control NamingContainer.
Greetings,
Iana
the Telerik team

http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/nestedviewtemplate/defaultcs.aspx
You'll just need to be careful about when and where you make that panel visible. I think usually you'll only need to do it during the item command:
protected
void
RadGrid1_ItemCommand(
object
source, GridCommandEventArgs e)
{
if
(e.CommandName == RadGrid.ExpandCollapseCommandName && e.Item
is
GridDataItem)
{
((GridDataItem)e.Item).ChildItem.FindControl(
"WrapperPanel"
).Visible =
!e.Item.Expanded;
}
}