Im attached the coding for bind the table items into the treeview control. step 1: create the table which consist the field such as bookid,bookname,author. step 2: Place 1 treeview control on our application] step 3: Use the coding below
Dim con As New SqlConnection
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load TreeView1.ExpandDepth = 1 End Sub Sub name(ByVal node As TreeNode) con.ConnectionString = "data source=.;integrated security=true" con.Open() Dim ds As New DataSet Dim da As New SqlDataAdapter("select * from author", con) da.Fill(ds) If ds.Tables.Count > 0 Then Dim row As DataRow For Each row In ds.Tables(0).Rows Dim newnode As TreeNode = New TreeNode newnode.Text = row("bookname").ToString() newnode.Value = row("bookid").ToString() 'MsgBox(row("bookid").ToString()) newnode.PopulateOnDemand = True newnode.SelectAction = TreeNodeSelectAction.Expand node.ChildNodes.Add(newnode) Next End If End Sub
Protected Sub TreeView1_TreeNodePopulate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView1.TreeNodePopulate If e.Node.ChildNodes.Count = 0 Then Select Case e.Node.Depth Case 0 name(e.Node) Case 1 bookname(e.Node) End Select End If End Sub
Sub bookname(ByVal node As TreeNode) con.ConnectionString = "data source=.;integrated security=true" con.Open() Dim ds As New DataSet Dim da As New SqlDataAdapter("select * from author where bookid='" + node.Value.ToString + "'", con) da.Fill(ds) If ds.Tables.Count > 0 Then Dim row As DataRow For Each row In ds.Tables(0).Rows Dim newnode As TreeNode = New TreeNode newnode.Text = row("author").ToString() 'MsgBox(row("bookname").ToString()) newnode.PopulateOnDemand = True newnode.SelectAction = TreeNodeSelectAction.Expand node.ChildNodes.Add(newnode) Next End If
End Sub
AttachmentsData Binding in to the Treeview control (34564-4312-Treeview.zip)
|
No responses found. Be the first to respond and make money from revenue sharing program.
|