|
| Re: Creating a category tree function |
 |
Tue, 25 Mar 2008 11:28:14 +000 |
[1] check out the code article at Vikram's Blog for this solution; here >
Using treeview control to show hierarchical data from the database
[2] alternate solution link > Populating the TreeView Control from a
Database (Parent Child)
[3] also you can visit this resolved thread link > treeview from a
database - ASP.NET Forums
hope it helps./.
|
| Post Reply
|
| Creating a category tree function |
 |
Tue, 25 Mar 2008 13:28:11 +000 |
Hi There,
Firstly Id like to say, sorry if this is in the wrong place, or if there is
already an answer for this out there. I have looked but couldnt find anything
that stood out.
I have been trying to create a function that prints out a list of categories
with their respective sub categories and such in a visually pleasing form from
an access database.
The effect Im after is that below:
Category 1
-- Category 1a
-- Category 1b
---- Category1bi
---- Category1bii
-- Category 1c
Category 2
-- Category 2a
and so on...
The database is a single table, where each row is linked to a parent row.
I have created this function already, but I think there is probably a much
better, and cleaner way of doing this:
1 Function BuildCategoryTree(output,parent_id,indent)
2 Dim SQL As String
3 DBconn = New OleDbConnection(ConfigurationSettings.AppSettings(
"dbConnection"))
4 DBconn.Open()
5
6 Dim cmdCategories As OleDbCommand
7 Dim dtrCategories As OleDbDataReader
8
9 SQL = "SELECT category_id, category_name, parent_id FROM categories WHERE
parent_id=" & parent_id
10
11 cmdCategories = New OleDbCommand(SQL, DBconn)
12
13 dtrCategories = cmdCategories.ExecuteReader()
14
15 If dtrCategories.HasRows then
16 While dtrCategories.Read()
17 Response.write(indent & dtrCategories("category_name") &
" " & dtrCategories("category_id") & " | "
& dtrCategories("parent_id") & "<br />")
18 If Not (dtrCategories("category_id") = parent_id)
19
BuildCategoryTree("",dtrCategories("category_id"),indent+&qu
ot;--")
20 End If
21 End While
22 End If
23
24 dtrCategories.Close()
25 DBconn.Close()
26 End Function
I really hope somebody can help me with this, or point me in the right
direction.
Thanks for reading and your help
Gaz
|
| Post Reply
|
| Re: Creating a category tree function |
 |
Tue, 25 Mar 2008 14:50:08 +000 |
PU43X:
The effect I am looking for is that of a tree view but not using the tree view
control.
I am looking at how I can populate a dropdown list with a similar layout
above.DropDownLists don't display hierarchical data. It's purely a list. What
you have already achieved is about as good as you can do with a DropDownList.
|
| Post Reply
|
| Re: Creating a category tree function |
 |
Tue, 25 Mar 2008 15:31:12 +000 |
Hi, Thanks for your reply.
The effect I am looking for is that of a tree view but not using the tree view
control.
I am looking at how I can populate a dropdown list with a similar layout above.
Thanks for your help.
|
| Post Reply
|
|
|
|
|
|
|
|
|
|