Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8345087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:34:25+00:00 2026-06-09T06:34:25+00:00

I have to develop a web part for SharePoint that reads a list and

  • 0

I have to develop a web part for SharePoint that reads a list and creates a tree view.

The tree view has to be organized as follows:
The root (or roots) is to be created by a choice field which represents a category, for instance Drinks,
the child nodes are the name of the rows that contain that category, the tree view has to be created programmatically.

List:
Title(string)       Category(Choice)
Coke            Drinks
Beer            Drinks
Fish            Food
Chips           Food

Would produce this:
Drinks
    Coke
    Beer
Food
    Fish
    Chips

code I have so far

  TreeView treeView;
    TreeNode rootNode;
    TreeNode childNode;


    protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
    {
        // render the control
        base.RenderContents(writer);
    }

    protected override void CreateChildControls()
    {
        List<TreeNode> items = new List<TreeNode>();

        base.CreateChildControls();

        // get the current site
        using (SPSite Site = new SPSite(SPContext.Current.Site.Url + "/UberWiki"))
        {
            using (SPWeb currentWeb = Site.OpenWeb())
            {

                // set the tree view properties



                SPList list = currentWeb.Lists["Pages"];

                SPFieldChoice field = (SPFieldChoice)list.Fields["Categories"];

                foreach (string str in field.Choices)
                {
                    treeView = new System.Web.UI.WebControls.TreeView();
                    rootNode = new System.Web.UI.WebControls.TreeNode(str);
                    treeView.Nodes.Add(rootNode);

                    foreach (SPListItem rows in list.Items)
                    {
                        childNode = new System.Web.UI.WebControls.TreeNode(rows.Title);
                        treeView.Nodes.Add(childNode);
                    }
                }
            }
            this.Controls.Add(treeView);
            base.CreateChildControls();
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:34:28+00:00Added an answer on June 9, 2026 at 6:34 am

    Another solution without the need to clean the multi choice string values

    using (SPSite Site = new SPSite(SPContext.Current.Site.Url + "/UberWiki"))
    {
        using (SPWeb currentWeb = Site.OpenWeb())
        {
            // set the tree view properties
            SPList list = currentWeb.GetList(currentWeb.Url+"/Lists/Pages");
    
            SPFieldChoice field = (SPFieldChoice)list.Fields["Categories"];
            treeView = new System.Web.UI.WebControls.TreeView();
    
            // Add root nodes
            foreach (string str in field.Choices)
            {
                rootNode = new System.Web.UI.WebControls.TreeNode(str);
                treeView.Nodes.Add(rootNode);                        
            }
    
            // Add child nodes
            foreach (SPListItem rows in list.Items)
            {
                childNode = new System.Web.UI.WebControls.TreeNode(rows["Title"].ToString());
                treeView.FindNode(rows["Categories"].ToString()).ChildNodes.Add(childNode);
            }
        }
        this.Controls.Add(treeView);
        base.CreateChildControls();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We will develop a web site that will have some free services and we
As part of a project, I have to develop a web application and a
I have develop one web site in php. I know how to upload it
I'll soon have to develop a web portal accessing a couchDB. Of course, I
I have been asked by my supervisor to develop a web application using either
I'm trying to develop a web application with Novell LDAP Authentication . I have
I have the 'luck' of develop and enhance a legacy python web application for
We have a web site with domain http://209.59.154.150/~phnxaudi/ ,. To develop this website we
Im trying to develop my first ASP.NET MVC web app and have run into
I have a suite of webpart controls that I maintain and develop for our

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.