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

How do I bind only one node?

3 Answers 32 Views
Navigation
This is a migrated thread and some comments may be shown as answers.
moegal
Top achievements
Rank 1
moegal asked on 27 Mar 2015, 03:45 PM
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



3 Answers, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 30 Mar 2015, 02:59 PM
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.

 
0
moegal
Top achievements
Rank 1
answered on 30 Mar 2015, 04:28 PM
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
0
Ivan Danchev
Telerik team
answered on 31 Mar 2015, 12:55 PM
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.

 
Tags
Navigation
Asked by
moegal
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
moegal
Top achievements
Rank 1
Share this question
or