Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Treeview > Dynamically fill treeview. (WIth 2 parameters)
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Not answered Dynamically fill treeview. (WIth 2 parameters)

Feed from this thread
  • Mak avatar

    Posted on May 3, 2011 (permalink)

    Hello, i just whant to ask if sombady can tellme if this way to fill my treeview looks correctley.

    I have this this calss:

        public class ReportType {
            public string Name { get; set; }
            public string[] PropertyNames { get; set; }
            public string[] PropertyTypes { get; set; }
        }

    And i have a list with this type of object. (Top)

    So what i whant to do, is fill my radtreeview with this objects, final result loocks like this

    Node1
             <b>SubNode1.1(Type)</b> + " " + SubNode1.1(Name)
             <b>SubNode1.1(Type)</b> + " " + SubNode1.1(Name)
    Node2
             <b>SubNode1.2(Type)</b> + " " + SubNode1.2(Name)
             <b>SubNode1.2(Type)</b> + " " + SubNode1.2(Name)

    So i have 2 parameteres (Type and Name) in each subnode text, and the first in BOLD. So that i do is the fallow:

                EntitiesTreeView.Nodes.Clear();
                ReportType[] types = this.Presenter.ReportGenerator.Types;
                foreach (ReportType type in types) {
                    RadTreeNode node = new RadTreeNode();
                    node.Text = type.Name;

                    for (int i = 0; i <= type.PropertyNames.Count() - 1; i++) {
                        RadTreeNode nodeProperty = new RadTreeNode();
                        nodeProperty.Controls.Add(GetTable(type.PropertyTypes[i], type.PropertyNames[i]));
                        node.Nodes.Add(nodeProperty);
                    }
                    EntitiesTreeView.Nodes.Add(node);
                }

            private HtmlTable GetTable(string propertyType, string propertyName) {
                HtmlTable table = new HtmlTable();
                HtmlTableRow row = new HtmlTableRow();

                HtmlTableCell cellPropertyType = new HtmlTableCell();
                cellPropertyType.InnerHtml = "<b>" + propertyType + "</b>";
                row.Cells.Add(cellPropertyType);

                HtmlTableCell cellPropertyName = new HtmlTableCell();
                cellPropertyName.InnerText = propertyName;
                row.Cells.Add(cellPropertyName);

                table.Rows.Add(row);
                return table;
            }



    Is this way looks nice? (Just whant to know if looks correctley)
    Thnx in advance.

  • Peter Peter admin's avatar

    Posted on May 11, 2011 (permalink)

    Hi Mak,

    Yes, this implementation seems quite fine to me. You can also take a look at the help topic on Adding and Editing Templates at Runtime. It shows a different approach, but if yours works, I don't see a reason why not to stay that way.


    Best wishes,
    Peter
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Treeview > Dynamically fill treeview. (WIth 2 parameters)