This is a migrated thread and some comments may be shown as answers.

Sql Databinding treeview control

1 Answer 127 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
vairam
Top achievements
Rank 1
vairam asked on 15 May 2009, 08:54 AM
Hi

How can i bind the sql datatable to treeview control.

Here i have loop all the records and bind the data table.How can i do that one without looping in Rad treeview control.

Dim daSuppliers As New SqlDataAdapter("SELECT CompanyName,SupplierID FROM Suppliers", objConn) 

Dim daProducts As New SqlDataAdapter("SELECT ProductName, ProductID, SupplierID FROM Products", objConn)

            daSuppliers.Fill(objDS, "dtSuppliers")

            daProducts.Fill(objDS, "dtProducts")
            //Giving the relation

objDS.Relations.Add("SuppToProd", _

    objDS.Tables("dtSuppliers").Columns("SupplierID"), _

    objDS.Tables("dtProducts").Columns("SupplierID"))

                Dim nodeSupp, nodeProd As TreeNode

                Dim rowSupp, rowProd As DataRow

For Each rowSupp In objDS.Tables("dtSuppliers").Rows

    nodeSupp = New TreeNode

    nodeSupp.Text = rowSupp("CompanyName")

    nodeSupp.value = rowSupp("SupplierID")

    TreeView1.Nodes.Add(nodeSupp)

         For Each rowProd In rowSupp.GetChildRows("SuppToProd")

             nodeProd = New TreeNode

             nodeProd.Text = rowProd("ProductName")

             nodeProd.value = rowProd("ProductID")

             nodeSupp.Nodes.Add(nodeProd)               

         Next

  Next

 

 

 

 

 

 

 


At the same time i need to improve the performance because supplier table has more than1000 records and product table has 3000 records.How can i do this one.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 18 May 2009, 09:57 AM
Hi Vairam,

I found some help articles on binding TreeView to DataTable. I guess the following links will shed some light on implementing the this.
Data Binding Overview
Binding to DataTable, DataSet or DataView
Binding to Hierarchical Data

Thanks,
Shinu.
Tags
TreeView
Asked by
vairam
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or