Web Treeview

Posted on 2012-09-13
Last Modified: 2012-10-27

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.
Question by:andyw27
    LVL 19

    Accepted Solution

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


    Author Comment

    Thanks, I like the idea of the hash table however how do you handle instances where you have two nodes with identical text?
    LVL 19

    Expert Comment

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


    Author Comment

    thanks, out of interest how do I get the value back out of the struct?

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now