Sql Databinding treeview control

2 posts, 0 answers
  1. vairam
    vairam avatar
    85 posts
    Member since:
    May 2008

    Posted 15 May 2009 Link to this post

    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.

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 18 May 2009 Link to this post

    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.
Back to Top