Hello Everybody,
I am new to .NET.
I need to build a treeview which must be populated from SQL Server
Database.
I tried to my level best,but couldnt find a solution for it.
I have a table called mn_doc_master.
doc_id int
cat_id int
short_title char(20)
doc_type char(1)
I need to populate the treeview based on this table.
cat_id is a category.
short_title is the text to appear on the node.
doc_type mentions wheather the current document is a folder or
document.
i have values like
1,0,'1st Folder','F'
2,1,'1-1 Document','D'
3,1,'1-2 Document','D'
4,0,'2nd Folder','F'
5,4,'2-1 Folder','F'
and so on...
I need to build a tree based on these values..it should be in
heirarchial manner like
1st Folder
1-1 Document
1-2 Document
2nd Folder
2-1 Folder
2-1-1 Folder
and so on..
I tried the following way.
----------------------------------------------------------------------------
Dim daDocs As New SqlClient.SqlDataAdapter("SELECT
short_title,doc_id,cat_id FROM mn_doc_master ORDER BY cat_id.doc_id ",
myConnection)
daDocs.Fill(objDS, "dtDocs")
Dim nodeDoc, nodeCat As TreeNode
Dim rowSupp, rowProd As DataRow
For Each rowSupp In objDS.Tables("dtDocs").Rows
nodeDoc = New TreeNode
nodeDoc.Text = rowSupp("short_title")
nodeDoc.ID = rowSupp("doc_id")
Dim cat_id = rowSupp("cat_id")
Treeview1.Nodes.AddAt(cat_id, nodeDoc)
Next
------------------------------------------------------------------------------
Thanks in Advance,