Click here to Skip to main content
13,291,084 members (58,229 online)
Click here to Skip to main content


65 bookmarked
Posted 16 Apr 2007

Auto Binding a TreeView control from a self referencing table

, 16 Apr 2007
A Custom TreeView Control that supports auto binding from a single self referencing table
Imports System
Imports System.Data
Imports System.Data.SqlClient

Partial Class DataBind
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            'Opens a connection to Database
            Dim oConn As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ToString())

            'Create Adapter and Fill Dataset
            Dim oAdapter As New SqlDataAdapter("SELECT * FROM SelfReferenceTable", oConn)
            Dim oDs As New DataSet

            'Close Connection
            oConn = Nothing

            'Close Adapter
            oAdapter = Nothing

            TestCtrl.DataFieldID = "ID"
            TestCtrl.DataFieldParentID = "ParentID"
            TestCtrl.DataTextField = "Text"
            TestCtrl.DataSource = oDs
        End If
    End Sub
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Bassam Saoud
Software Developer (Senior) Delcan Corporation
United States United States
Bassam Saoud is a software developer with more then 6+ years of experience. He has masters in Computer Science from American University of Technology and is currently doing Masters in Business Administration at Colorado Heights University. He started Programming with C++ and VB and now working with ASP.NET VB.NET/C#, SQL Server 2000/2005.

His interests are mainly politics, Basketball and Traveling.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 16 Apr 2007
Article Copyright 2007 by Bassam Saoud
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid