NestedViewTemplate Programmatic binding

17 posts, 0 answers
  1. Josh
    Josh avatar
    42 posts
    Member since:
    May 2009

    Posted 03 Nov 2009 Link to this post

    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


     
  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 04 Nov 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. John John
    John John avatar
    132 posts
    Member since:
    Aug 2009

    Posted 04 Nov 2009 Link to this post

    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 

  5. Josh
    Josh avatar
    42 posts
    Member since:
    May 2009

    Posted 04 Nov 2009 Link to this post

    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 

  6. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 09 Nov 2009 Link to this post

    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.
  7. Patrik
    Patrik avatar
    1 posts
    Member since:
    Aug 2007

    Posted 17 Feb 2010 Link to this post

    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.

  8. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 18 Feb 2010 Link to this post

    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.
  9. naru
    naru avatar
    11 posts
    Member since:
    Sep 2010

    Posted 08 Sep 2010 Link to this post

    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.
  10. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 08 Sep 2010 Link to this post

    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
  11. naru
    naru avatar
    11 posts
    Member since:
    Sep 2010

    Posted 08 Sep 2010 Link to this post


    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!
  12. naru
    naru avatar
    11 posts
    Member since:
    Sep 2010

    Posted 13 Sep 2010 Link to this post

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


  13. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 16 Sep 2010 Link to this post

    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
  14. naru
    naru avatar
    11 posts
    Member since:
    Sep 2010

    Posted 16 Sep 2010 Link to this post

    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...
  15. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 17 Sep 2010 Link to this post

    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
  16. Dathuraj
    Dathuraj avatar
    1 posts
    Member since:
    Oct 2010

    Posted 25 Oct 2010 Link to this post

    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.

  17. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 26 Oct 2010 Link to this post

    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
  18. Merritt
    Merritt avatar
    28 posts
    Member since:
    Mar 2011

    Posted 16 Mar 2012 Link to this post

    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;
        }
    }
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017