Web Treeview


I'm building a web page that has treeview control.  The data for the treeview is derived from a database.  Is it possible to have the treeview node display one piece of text but also store an additional value which can be accessed by the program?
I thought of doing this by a tag property but this doesn't seem to be available in web tree view control.
Who is Participating?
Daniel Van Der WerkenConnect With a Mentor Independent ConsultantCommented:
Would the TagName property work for this?

One thing I've done is create an "associated" HashTable that hold values. Then, for each TreeView node text value  you add, add the additional value to the HashTable:

HashTable additionalValues = new HashTable();
...for each new TreeView Node:
    treeview1.Nodes.Add(  myNode );
   additionalValues[ myNode.Text ] = additionalValueForNode;
... and so forth.

then, when the user clicks on the node, you grab the selected node text and do a lookup by seeing the value:

object myValue = additionalValues[ selectedNode.Text ];

andyw27Author Commented:
Thanks, I like the idea of the hash table however how do you handle instances where you have two nodes with identical text?
Daniel Van Der WerkenIndependent ConsultantCommented:
Since the HashTable can handle any object, use a struct:
public struct MyMostExcellentStruct
   public string MyMostExcellentString;
   public int MyMostExcellentInt;

for each new Node....
    MyMostExcellentStruct mmes = new MyMostExcellentStruct();
    mmes.MyMostExcellentString = "Some Extremely Excellent String Value";
    mmes.MyMostExcellentInt = 12345;

    additionalValues[ myNode.Text ] = mmes;


Open in new window

andyw27Author Commented:
thanks, out of interest how do I get the value back out of the struct?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.