recursive relation in datagrid

S

Sandeman

I have a table with this structure
itemID
naam
image
parentID

I want to make a datagrid that contains a hyperlinkcolumn. When i click on
the hyperlink i want the subitems to become the items in the same datagrid.
(the former items will disappear and we can call them back with the button
'Back'.

For example:

I have this table tblComponents
itemID | name | image | parentID |
1 | car | ---- | ------ |
2 | wheels | ----- | 1 |
3 | chassis | ----- | 1 |

In the first view i want to see this
itemID | name |
1 | car |

After i click on car (it's a hyperlink button) i want a view like this
itemID | name
2 | wheels |
3 | chassis |


Can anybody help me with this?
 
A

Arthur Dent

Make a template column, stick in a linkbutton, and give it a CommandName =
"drilldown" or something else appropriate.
Bind the linkbutton's CommandArgument property to the itemID property. Then
in your codebehind, handle the grids ItemCommand event. Then do something of
the nature:

Sub ItemCommand (...) handles grd.ItemCommand
If e.CommandName = "drilldown" Then
Dim SQL as string = "SELECT * FROM MYTABLE WHERE parentID = " &
e.CommandArgument
grd.DataSource = BuildDataTable(SQL) '// some fictional procedure to
build the table with the SQL
grd.DataBind
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top