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

Find and select a node in TreeView

1 Answer 66 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Mario
Top achievements
Rank 1
Mario asked on 18 Jan 2012, 04:45 PM
Hello,
i make a RadTreeView so:
<telerik:RadTreeView ID="RadTreeView1" Runat="server" DataFieldID="playerID"
                  DataFieldParentID="parentID" DataSourceID="ObjectDataSource1"
                  DataTextField="playerName" DataValueField="Route"
                  onnodedatabound="RadTreeView1_NodeDataBound" 
                    Width="100%" oncontextmenuitemclick="RadTreeView1_ContextMenuItemClick">

It works fine.
playerID - Primary key
parentID - for TreeView
playerName - String
Route - a value between 1 to 4 (1-Main, 2-Partial, ...)

Once a new record is inserted into the database, I get back the new playerID.

PlayerBLL players = new PlayerBLL();
        string text = SaveSQL.GetSaveSql(txtCreateMainRouteName.Text.Trim());       
 
        if (Page.IsValid)
        {
            PlayerID = players.InsertRouteAndStation(text, 1, null);
            RadTreeView1.DataSourceID = "ObjectDataSource1";
            RadTreeView1.DataBind();
        }

How can i select the new Node in the TreeView with the new playerID?

Best regards
Reiner

1 Answer, 1 is accepted

Sort by
0
Bozhidar
Telerik team
answered on 18 Jan 2012, 05:41 PM
Hi Mario,

You cannot directly use the item ID, because it is not bound to any public property of the treeview. The DataFieldID is only used internaly to bind the TreeView and it's not available on the server.

To implement the search, you can use the NodeDataBound server event, where you can set a custom attribute of the node, holding the playerID value. Then you can just use the server method FindNodeByAttribute. Here's a small example:
protected void RadTreeView1_NodeDataBound(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e)
{
    e.Node.Attributes.Add("playerID", (e.Node.DataItem as DataRowView)["playerID"].ToString());
}
 
protected RadTreeNode FindNode(string id)
{
    return RadTreeView1.FindNodeByAttribute("playerID", id);
}

 
Greetings,
Bozhidar
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
TreeView
Asked by
Mario
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Share this question
or