C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Databinding »

Binding the table item into the treeview


Posted Date: 04 Nov 2009    Resource Type: Code Snippets    Category: Databinding
Author: subhashiniMember Level: Silver    
Rating: 1 out of 5Points: 5



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


Attachments

  • Data Binding in to the Treeview control (34564-4312-Treeview.zip)


  • Responses


    No responses found. Be the first to respond and make money from revenue sharing program.

    Feedbacks      
    Popular Tags   What are tags ?   Search Tags  
    Sign In to add tags.
    Data binding in treeview control  .  

    Post Feedback


    This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
    You must Sign In to post a response.
    Next Resource: Tree databinding in vb.net and sql 2005
    Return to Discussion Resource Index
    Post New Resource
    Category: Databinding


    Post resources and earn money!
     
    More Resources



    dotNet Slackers

    About Us    Contact Us    Privacy Policy    Terms Of Use