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

DataValueField but no attribute

3 Answers 109 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Michel
Top achievements
Rank 1
Michel asked on 14 Dec 2011, 11:23 AM
Hi,

I have a problem with the attributes (DataValueField), this is my code :
treeView.DataTextField = "CheminFr";
treeView.DataFieldID = "CLA_CODE";
treeView.DataFieldParentID = "PARENT_CLA_CODE";
treeView.DataValueField = "CLA_ID";           
treeView.DataValueField = "CLA_ACTIVE";
treeView.DataValueField = "profondeur";
treeView.DataValueField = "cheminEn";
treeView.DataValueField = "ChildrenAllowed";
treeView.DataValueField = "nbArticle";
 
//Récupère l'arbre à afficher
DataSet ds = MichelFactory.getAllHierarchy();
 
treeView.DataSource = ds;
treeView.DataBind();

In debug mode,
ds.Tables[0].Rows[0]["nbArticle"] = 52 but treeView.Nodes[0].Attributes.Count = 0 :-/

The tree is displayed correctly... but I can't find the attributes.

Do you have an idea?






3 Answers, 1 is accepted

Sort by
0
Michel
Top achievements
Rank 1
answered on 14 Dec 2011, 12:17 PM
I'm sorry!!

To add attributes, I must use :

e.Node.Attributes.Add(.../...) on RadTreeView_NodeDataBound

Sorry, sorry, and I can't delete this thread :-(
0
Bozhidar
Telerik team
answered on 14 Dec 2011, 12:57 PM
Hi Michel,

The RadTreeNode attributes collection and DataValueField are two different things. DataValueField is used to bind the value of the node. To bind additional attributes, you have to do it in the OnNodeDataBound event. For instance, if you want to bind the profounder property to an attribute called Profounder, you shoud do the following:

protected void RadTreeView1_NodeDataBound(object sender, RadTreeNodeEventArgs e)
{
    e.Node.Attributes["Profoundeur"] = ((NodeDataItem)e.Node.DataItem).profondeur;
}
Regards,
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
0
Michel
Top achievements
Rank 1
answered on 14 Dec 2011, 03:02 PM
Thanks Bozhidar

I use :

e.Node.Attributes["profondeur"] = ((System.Data.DataRowView)(e.Node.DataItem)).Row.ItemArray[4].ToString();

Because my treeView.DataSource is a DataSet.
Tags
TreeView
Asked by
Michel
Top achievements
Rank 1
Answers by
Michel
Top achievements
Rank 1
Bozhidar
Telerik team
Share this question
or