How to Access value of CheckedNodes in RadTeeView ServerSide

1 Answer 43 Views
TreeView
Juergen
Top achievements
Rank 1
Juergen asked on 09 Jun 2023, 06:41 AM

I'm using RadListBox as as RadTreeview in my page.

I'm binding data to RadTreeview with:

            List<SiteDataItem> siteData = GetNotificationTree();

            treeView.DataTextField = "Text";
            treeView.DataFieldID = "ID";
            treeView.DataFieldParentID = "ParentID";
            treeView.DataSource = siteData;
            treeView.DataBind();

 

Serverside I want to read the Value of the checked items. In Listbox that works with:

ListBox.CheckedItems.Select(_ => int.Parse(_.Value))

But in Treeview I'm not able to access the values e.g. with:

Treeview..CheckedNodes.Select(_ =>int.Parse(_.Value)). I'm only able to read the text property but not the value bound to the TreeView.

 

1 Answer, 1 is accepted

Sort by
0
Doncho
Telerik team
answered on 13 Jun 2023, 12:52 PM

Hi Juergen,

The approach seems correct.

Please make sure there are no JavaScript errors on the page:

Could you please share the entire declaration of the RadTreeView along with the relevant code-behind logic so I can get a better understanding of the scenario?

Here is a basic sample I tested on my end and works as expected:

<asp:Label Text="Checked values: " runat="server" />
<asp:Label Text="" runat="server" ID="Label1" />

<telerik:RadTreeView runat="server" RenderMode="Lightweight" ID="RadTreeView1" CheckBoxes="true">
    <Nodes>
        <telerik:RadTreeNode Text="Root 1" Value="1" Expanded="true">
            <Nodes>
                <telerik:RadTreeNode Text="Child 1.1" Value="11"></telerik:RadTreeNode>
                <telerik:RadTreeNode Text="Child 1.2" Value="12"></telerik:RadTreeNode>
                <telerik:RadTreeNode Text="Child 1.3" Value="13"></telerik:RadTreeNode>
                <telerik:RadTreeNode Text="Child 1.4" Value="14"></telerik:RadTreeNode>
            </Nodes>
        </telerik:RadTreeNode>
        <telerik:RadTreeNode Text="Root 2" Expanded="true" Value="10">
        </telerik:RadTreeNode>

    </Nodes>
</telerik:RadTreeView>

<telerik:RadButton runat="server" ID="RadButton1" Text="Get Checked Values" AutoPostBack="true" OnClick="RadButton1_Click" />

C#

protected void RadButton1_Click(object sender, EventArgs e)
{
    Label1.Text = "";
    var checkedValues = RadTreeView1.CheckedNodes.Select(_ => int.Parse(_.Value));
    foreach (var val in checkedValues)
    {
        Label1.Text += val + "; ";
    }

}

Kind regards,
Doncho
Progress Telerik

Heads up! Telerik UI for ASP.NET AJAX versions for .NET 3.5 and 4.0 are retired. Progress will continue shipping assemblies compatible with .NET 4.5 and later. See whether this affects your apps in this article.
Tags
TreeView
Asked by
Juergen
Top achievements
Rank 1
Answers by
Doncho
Telerik team
Share this question
or