Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Web Treeview

Posted on 2012-09-13
4
Medium Priority
?
466 Views
Last Modified: 2012-10-27
Hi,

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.
0
Comment
Question by:andyw27
  • 2
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
Daniel Van Der Werken earned 2000 total points
ID: 38396331
Would the TagName property work for this?
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webcontrol.tagname(v=vs.90)

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 ];

etc.
0
 

Author Comment

by:andyw27
ID: 38396384
Thanks, I like the idea of the hash table however how do you handle instances where you have two nodes with identical text?
0
 
LVL 20

Expert Comment

by:Daniel Van Der Werken
ID: 38400072
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

0
 

Author Comment

by:andyw27
ID: 38451071
thanks, out of interest how do I get the value back out of the struct?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month21 days, 2 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question