ASP.NET 3.5 and above only

ASP.NET TreeView - Binding With ObjectDataSource Binding

  • President
    • Vice President
      • CEO
        • Project Manager
          • Team Laeder 1
            • Engineer 1
            • Engineer 2
          • Team Leader 2
            • Engineer 1
            • Engineer 2
[ASPX]
   
            <obout:Tree ID="OboutTree1" CssClass="vista" DataSourceID="ObjectDataSource1"
                runat="server">
                <DataBindings>
                    <obout:NodeBinding 
                        DataSourceColumnID="ID" 
                        DataSourceColumnParentID="ParentID"
                        TextField="Name" ImageUrlField="ImagePath" 
                        Expanded="true" />
                </DataBindings>
            </obout:Tree>
            <asp:ObjectDataSource ID="ObjectDataSource2" TypeName="Roles" SelectMethod="GetRoles"
                runat="server">
            </asp:ObjectDataSource>
            
[Roles.cs]
 
            using System;
            using System.Collections.Generic;
            using System.Linq;
            using System.Web;
            public class Roles
            {
                private string _name;
                private string _id;
                private string _parentId;
                private string _imagePath;

                public string Name
                {
                    get { return _name; }
                    set { _name = value; }
                }


                public string ID
                {
                    get { return _id; }
                    set { _id = value; }
                }

                public string ParentID
                {
                    get { return _parentId; }
                    set { _parentId = value; }
                }

                public string ImagePath
                {
                    get { return _imagePath; }
                    set { _imagePath = value; }
                }

                public Roles(string id, string parentId, string name, string imgPath)
                {
                    _id = id;
                    _parentId = parentId;
                    _name = name;
                    _imagePath = imgPath;
                }

                public static List<Roles> GetRoles()
                {
                    List<Roles> roles = new List<Roles>();

                    roles.Add(new Roles("1", null, "President", "~/obout.ajax.ui/treeview/examples/img/boss-icon.png"));
                    roles.Add(new Roles("2", "1", "Vice President", "~/obout.ajax.ui/treeview/examples/img/engineer-icon.png"));
                    roles.Add(new Roles("3", "2", "CEO", "~/obout.ajax.ui/treeview/examples/img/engineer-icon.png"));
                    roles.Add(new Roles("4", "3", "Project Manager", "~/obout.ajax.ui/treeview/examples/img/engineer-icon.png"));
                    roles.Add(new Roles("5", "4", "Team Laeder 1", "~/obout.ajax.ui/treeview/examples/img/engineer-icon.png"));
                    roles.Add(new Roles("6", "5", "Engineer 1", "~/obout.ajax.ui/treeview/examples/img/user-icon.png"));
                    roles.Add(new Roles("7", "5", "Engineer 2", "~/obout.ajax.ui/treeview/examples/img/user-icon.png"));
                    roles.Add(new Roles("8", "4", "Team Leader 2", "~/obout.ajax.ui/treeview/examples/img/engineer-icon.png"));
                    roles.Add(new Roles("9", "8", "Engineer 1", "~/obout.ajax.ui/treeview/examples/img/user-icon.png"));
                    roles.Add(new Roles("10", "8", "Engineer 2", "~/obout.ajax.ui/treeview/examples/img/user-icon.png"));

                    return roles;
                }
            }
            
Roles.vb

            Imports System
            Imports System.Collections.Generic
            Imports System.Linq
            Imports System.Web
            Public Class Roles
                Private _name As String
                Private _id As String
                Private _parentId As String
                Private _imagePath As String

                Public Property Name() As String
                    Get
                        Return _name
                    End Get
                    Set(ByVal value As String)
                        _name = value
                    End Set
                End Property


                Public Property ID() As String
                    Get
                        Return _id
                    End Get
                    Set(ByVal value As String)
                        _id = value
                    End Set
                End Property

                Public Property ParentID() As String
                    Get
                        Return _parentId
                    End Get
                    Set(ByVal value As String)
                        _parentId = value
                    End Set
                End Property

                Public Property ImagePath() As String
                    Get
                        Return _imagePath
                    End Get
                    Set(ByVal value As String)
                        _imagePath = value
                    End Set
                End Property

                Public Sub New(ByVal id As String, ByVal parentId As String, ByVal name As String, ByVal imgPath As String)
                    _id = id
                    _parentId = parentId
                    _name = name
                    _imagePath = imgPath
                End Sub

                Public Shared Function GetRoles() As List(Of Roles)
                    Dim roles As New List(Of Roles)()

                    roles.Add(New Roles("1", Nothing, "President", "~/obout.ajax.ui/treeview/examples/img/boss-icon.png"))
                    roles.Add(New Roles("2", "1", "Vice President", "~/obout.ajax.ui/treeview/examples/img/engineer-icon.png"))
                    roles.Add(New Roles("3", "2", "CEO", "~/obout.ajax.ui/treeview/examples/img/engineer-icon.png"))
                    roles.Add(New Roles("4", "3", "Project Manager", "~/obout.ajax.ui/treeview/examples/img/engineer-icon.png"))
                    roles.Add(New Roles("5", "4", "Team Laeder 1", "~/obout.ajax.ui/treeview/examples/img/engineer-icon.png"))
                    roles.Add(New Roles("6", "5", "Engineer 1", "~/obout.ajax.ui/treeview/examples/img/user-icon.png"))
                    roles.Add(New Roles("7", "5", "Engineer 2", "~/obout.ajax.ui/treeview/examples/img/user-icon.png"))
                    roles.Add(New Roles("8", "4", "Team Leader 2", "~/obout.ajax.ui/treeview/examples/img/engineer-icon.png"))
                    roles.Add(New Roles("9", "8", "Engineer 1", "~/obout.ajax.ui/treeview/examples/img/user-icon.png"))
                    roles.Add(New Roles("10", "8", "Engineer 2", "~/obout.ajax.ui/treeview/examples/img/user-icon.png"))

                    Return roles
                End Function
            End Class
            

"I want to compliment you guys on your outstanding support. Love using your products especially with such great support."

Orson Tormey
Trio Technology

Random testimonial   All testimonials