If I have this [Terminal] table:
ID bigint
Description varchar(20)
TerminalLevel smallint //1 = Terminal, 2 = Sub Terminal, 3 = Sub-sub-Terminal
TerminalID //0 = Main Terminal itself, else belong to parent terminal
For example, I have:
ID Description TerminalLevel TerminalID
1 Terminal 1 1 0
2 Terminal 1-1 2 1
3 Terminal 1-1-1 3 2
4 Terminal 2 1 0
5 Terminal 2-1 1 4
I expect to load the data to the tree like this:
Terminal 1
|---> Terminal 1-1
|---> Terminal 1-1-1
Terminal 2
|---> Terminal 2-1
Would it be possible to select only one query and load to a treeview in asp.net?
Get you query in a
sqldatareader DReaderbut order byTerminalIDto avoid child to be added before parentand use the following functions
UPDATE
if you are using sqldatareader you only need to order by terminalid and with advance of terminallevel you can use my solution, if you are using datatable or store data in a collection, you can use the solution of two functions to bind treeview one have parentNode of tree …
but here you have terminal level so you can search in node by path
My Regards