I need to create a nested linkbuttons in a asp.net page that looks like a treeview, but all are linkbuttons. Example is shown below:
ParentLinkButton1
ChildLinkButton1
ChildLinkButton2
ChildLinkButton3
ParentLinkButton2
ChildLinkButton1
ChildLinkButton2
ParentLinkButton3
ParentLinkButton4
ChildLinkButton1
I really don't know how to do this. Based on my research this can be done using repeated control but I don't know how to do that... Please if you can teach me step by step...
Thanks in advance!
The following example uses a ListView instead of a Repeater. ListViews are great because they'll give you much more flexibility over a Repeater. Moreover, as you can see in the sample code below, binding the nested/child ListView can all be done declaratively without any code-behind.
Example of what the following code will produce
ASPX
C#
As you can see, in the C# code, I've created a list of "Person" as follows. Each Person object has a list of child Person objects. By creating your objects in this manner, binding the ListView is really as simple as I've shown. Use the Person object below to run a quick sample so you can see for yourself.
Person object
For your test, you can create a Page_Load method as follows:
See the following StackOverflow question to learn more about the differences between a Repeater and a ListView: Repeater, ListView, DataList, DataGrid, GridView ... Which to choose?
I would recommend doing a repeater inside of a repeater.
And then in the ItemDataBound events you can set the data source for the child repeater and bind it.
Feel free to ask for any clarifications. i don't want to write the whole thing for you.
EDIT:
To bind the parent, you would want to use Page Load or some other page event to add the datasource to the outer repeater and then bind it.
And then you have 2 options, wither the way I showed it in the asp above by accessing your databound object using the eval, or by using the parent's ItemDataBound event.
The above code is not perfect, but it should get you a good idea on how to get the rest of the way,
Cheers,