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

Problem in Custom Attributes

1 Answer 30 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Eng.Bassel Samman
Top achievements
Rank 2
Eng.Bassel Samman asked on 17 Oct 2010, 10:00 AM
Dear,
I add new custom attribute to RadTreeNode using the following code:

Nod.Attributes.Add("Key", "Value")
Where Nod is a RadTreeNode, the attributes is added (Node attributes count is increased) but when I retrieved its value using: Nod.Attributes(Key) I always got Nothing.
Best Regards


1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 18 Oct 2010, 10:14 AM
Hello,

Checkout the following example which shows how to add custom attributes in NodeDataBound event.

ASPX:
 
<telerik:RadTreeView ID="RadTreeView2" runat="server" DataFieldID="CategoryID" DataSourceID="SqlDataSource1" 
    DataTextField="CategoryID" OnNodeDataBound="RadTreeView2_NodeDataBound" OnNodeClick="RadTreeView2_NodeClick"
</telerik:RadTreeView> 

C#:
 
protected void RadTreeView2_NodeDataBound(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e) 
    DataRowView dataSourceRow = (DataRowView)e.Node.DataItem; 
    //set custom attributes from the datasource:   
    e.Node.Attributes["CategoryName"] = dataSourceRow["CategoryName"].ToString();   
protected void RadTreeView2_NodeClick(object sender, RadTreeNodeEventArgs e) 
    String Name = e.Node.Text.ToString(); 
    String CategoryName = RadTreeView2.SelectedNode.Attributes["CategoryName"]; 
    Response.Write("You have selected " + Name + " with Name " + CategoryName);   


Check with the example and see what you are missing in your code.


-Shinu.
Tags
TreeView
Asked by
Eng.Bassel Samman
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Share this question
or