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

NestedViewTemplate Programmatic binding

16 Answers 913 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 03 Nov 2009, 11:42 PM
Hello all,

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

Sort by
0
Pavlina
Telerik team
answered on 04 Nov 2009, 09:50 AM
Hi Josh,

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.
0
John John
Top achievements
Rank 1
answered on 04 Nov 2009, 12:17 PM
Hi
    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 

0
Josh
Top achievements
Rank 1
answered on 04 Nov 2009, 02:19 PM
Pavlina,

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 

0
Pavlina
Telerik team
answered on 09 Nov 2009, 03:03 PM
Hello 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.
0
Patrik
Top achievements
Rank 2
answered on 17 Feb 2010, 02:40 PM
And the question, as I understand it, is:
 
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.

0
Pavlina
Telerik team
answered on 18 Feb 2010, 04:07 PM
Hi Patrik,

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.
0
naru
Top achievements
Rank 1
answered on 08 Sep 2010, 11:34 AM
Hello Pavlina,

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.
0
Pavlina
Telerik team
answered on 08 Sep 2010, 12:57 PM
Hi Naru,

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
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
0
naru
Top achievements
Rank 1
answered on 08 Sep 2010, 05:41 PM

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!
0
naru
Top achievements
Rank 1
answered on 13 Sep 2010, 05:35 PM
Hello Pavlina,

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 :)


0
Pavlina
Telerik team
answered on 16 Sep 2010, 03:17 PM
Hello Naru,

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
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
0
naru
Top achievements
Rank 1
answered on 16 Sep 2010, 06:50 PM
Hello Pavlina,

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...
0
Iana Tsolova
Telerik team
answered on 17 Sep 2010, 02:55 PM
Hello naru,

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
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
0
Dathuraj
Top achievements
Rank 1
answered on 25 Oct 2010, 04:26 PM
I am using 2008.03.1016.35 version of telerik controls. I am trying to create a NestedViewTemplate grid,  its unable to find "ParentItem" property.

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.

0
Iana Tsolova
Telerik team
answered on 26 Oct 2010, 10:35 AM
Hello Dathuraj,

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
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
0
Merritt
Top achievements
Rank 1
answered on 16 Mar 2012, 08:51 PM
My 2 cents here: on the first page load, you'll be fetching the data source for each record's nested view's grid... this is not a good thing. You'll need to wrap the contents of your grid with something that will disable your grid's need data source event from firing. I have found this desired behavior by wrapping the whole template in a panel and initializing it to visible = false, much like in this demo:

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;
    }
}
Tags
Grid
Asked by
Josh
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
John John
Top achievements
Rank 1
Josh
Top achievements
Rank 1
Patrik
Top achievements
Rank 2
naru
Top achievements
Rank 1
Iana Tsolova
Telerik team
Dathuraj
Top achievements
Rank 1
Merritt
Top achievements
Rank 1
Share this question
or