views:

123

answers:

2

I have a have a table with Region_Name, Region_ID fields, and another one with Area_Name, Region_ID fields (each region have Areas that belongs to it). I want to display on my asp.net page a list of links (something that looks like a treeView) so when someone clicks on for ex The Bronx from Region New York in this list:

  • New York

    • The Bronx

    • Brooklyn

    • Manhattan

  • Kentucky

    • Ashland

    • Bardstown

  • New Jersey

    • Essex

    • Middlesex

etc....etc... So, apart from the basics, i want to know how to populate the above list Automatically and make sure that the results are ALL Links, in other words, New York is a link, The Bronx is a link, and all the elements in the list are links that i will later attach a queryString to...

I am using VB.Net and ASP.Net 3.5. Thanks in advance

+1  A: 

If you want to do it declaratively then use nested Repeater controls. The outside one to loop through the Region table and the inside for the Areas, based on the region ID of course.

One simple way to do nested repeaters is to use a DataSet and create a relationship between the two relevant DataTables.

Here's a good example: http://jamesewelch.wordpress.com/2008/03/06/how-to-use-nested-repeater-controls-with-relational-data/

Iain M Norman
+1  A: 

Thanks for all who answered or attempted to. I found out a different yet easy solution:

In my page_load i called:

labelwhatever.text = outputRegionAsLinks()

and the function is:

Private Function outputRegionAsLinks() As String
    Dim sb As New StringBuilder
    Dim regionsTable As GKP.tblRegionsDataTable = Regions.GetRegions()

    For Each region In regionsTable
        sb.Append("<a href=''>")
        sb.Append(region.RegionName)
        sb.Append("</a>")
        sb.Append("<br />")
    Next



    Return sb.ToString

End Function

This way i can avoid the overload of creating asp link buttons or hyperlinks, and directly inject html tags in my form, and also tailor the links as i wish them to be.

Maen