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?