How do I bind only one node?

4 posts, 0 answers
  1. moegal
    moegal avatar
    273 posts
    Member since:
    Jul 2007

    Posted 27 Mar 2015 Link to this post

    How do I bind only one node to a datatable or dataset(or sqldatasource I would like to use cache so it does not load every call as well)

    <telerik:RadNavigation ID="RadNavigation1" runat="server" CssClass="siteMainMenu">
                    <Nodes>
                        <telerik:NavigationNode ID="NavigationNode1" Text="Home" runat="server" NavigateUrl="/">
                        </telerik:NavigationNode>
                        <telerik:NavigationNode ID="NavigationNode2" Text="Products" runat="server">
                        </telerik:NavigationNode>
                        <telerik:NavigationNode ID="NavigationNode3" Text="Support" runat="server">
                            <Nodes>
                                <telerik:NavigationNode Text="Tutorials"></telerik:NavigationNode>
                                <telerik:NavigationNode Text="Samples"></telerik:NavigationNode>
                            </Nodes>
                        </telerik:NavigationNode>               
                    </Nodes>
                </telerik:RadNavigation>


    I have a dynamic list of products that I want to display as a drop down under NavigationNode2 "Products".

    I suspect I would do something on nodedatabound but not sure what? 

    Thanks, Marty



  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    834 posts

    Posted 30 Mar 2015 Link to this post

    Hello Marty,

    If you bind the RadNavigation through its DataSourceIdD property it will not display the Nodes you have added in the markup and replace them with the data from the data source you provided. You can use the approach in the following code snippet to bind a particular RadNavigationNode:
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetItems(RadNavigation1.Nodes[1]);
        }
    }
     
    private void GetItems(NavigationNode navigationNode)
    {
        // ... get necessary data from DataSet (like "Text") and use it to set the items properties
     
     
        for (int i = 0; i < 10; i++)
        {
            navigationNode.Nodes.Add(new NavigationNode { Text = "Item" + i, NavigateUrl = "" });
        }
    }

    After you get the data from your data source for the nodes you want to add to a particular node (in the example that is the RadNavigation's second root node) you can add those nodes and set their properties accordingly. So instead of adding 10 nodes with Text="Item" + i and an empty NavigateUrl, as shown in the example, you would access the corresponding data in your data source and add a specific number of nodes and pass the specific Text and NavigateUrl values. Note that the GetItems() method is called only in when the page loads, not on every postback.

    Regards,
    Ivan Danchev
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. moegal
    moegal avatar
    273 posts
    Member since:
    Jul 2007

    Posted 30 Mar 2015 in reply to Ivan Danchev Link to this post

    Ivan,

    thanks. Where would I add the DataFieldID  and the DataFieldParentID. NavigationNode does not seem to support this? 
    The data for this node is hierarchical. 

    Marty
  5. Ivan Danchev
    Admin
    Ivan Danchev avatar
    834 posts

    Posted 31 Mar 2015 Link to this post

    Hello,

    The RadNavigationNode does not have the DataFieldID and DataFieldParentID properties that are available to the RadNavigation. If you want to bind only one node you have to do it without using those properties getting the necessary data from the data source, manually creating the hierarchy and setting the properties of each of the child nodes as in the example from my previous reply.

    Regards,
    Ivan Danchev
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top