RadNavigation

1 Answer 23 Views
Navigation
SSirica
Top achievements
Rank 2
Iron
Iron
Veteran
SSirica asked on 20 Apr 2022, 05:16 PM
Why would you include a FindNodeByText function, but not include a FindNodeByID function?  You allow an ID to be assigned to a NavigationNode...logic dictates you should be able to find it by the ID.

1 Answer, 1 is accepted

Sort by
0
Accepted
Peter Milchev
Telerik team
answered on 25 Apr 2022, 12:06 PM

Hello SSirica,

The nodes can have an ID and they can be accessed directly by it. That is why having a FindById method would be redundant. 

On the other hand, if for some reason such access is not possible, you can LINQ to find a node by any property or attribute, or a simple foreach loop:

<telerik:RadNavigation runat="server" ID="RadNavigation1" RenderMode="Lightweight">
    <Nodes>
        <telerik:NavigationNode Text="Root 1"></telerik:NavigationNode>
        <telerik:NavigationNode Text="Root 2">
            <Nodes>
                <telerik:NavigationNode Text="Child 2.1" ID="Child21"></telerik:NavigationNode>
                <telerik:NavigationNode Text="Child 2.2" ID="Child22">
                    <Nodes>
                        <telerik:NavigationNode Text="Grand Child 2.2.1"></telerik:NavigationNode>
                        <telerik:NavigationNode Text="Grand Child 2.2.2"></telerik:NavigationNode>
                        <telerik:NavigationNode Text="Grand Child 2.2.3"></telerik:NavigationNode>
                        <telerik:NavigationNode Text="Grand Child 2.2.4"></telerik:NavigationNode>
                    </Nodes>
                </telerik:NavigationNode>
                <telerik:NavigationNode Text="Child 2.3"></telerik:NavigationNode>
                <telerik:NavigationNode Text="Child 2.4"></telerik:NavigationNode>
            </Nodes>
        </telerik:NavigationNode>
    </Nodes>
</telerik:RadNavigation>

using System;
using System.Linq;

public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Child21.Text = "Child 2.1 changed from the server";

        var node = RadNavigation1.GetAllNodes().FirstOrDefault(x => x.ID == "Child22");
        if (node != null)
        {
            node.Text = "Child 2.2 changed from the server";
        }
    }
}

Regards,
Peter Milchev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

SSirica
Top achievements
Rank 2
Iron
Iron
Veteran
commented on 25 Apr 2022, 12:28 PM

Cool thanks.
Tags
Navigation
Asked by
SSirica
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Peter Milchev
Telerik team
Share this question
or