类似树形视图的链接列表

发布于 2024-07-14 15:52:18 字数 600 浏览 2 评论 0原文

我有一个包含 Region_Name、Region_ID 字段的表,另一个包含 Area_Name、Region_ID 字段的表(每个区域都有属于它的区域)。 我想在我的 asp.net 页面上显示一个链接列表(看起来像树视图),因此当有人单击此列表中的纽约地区前布朗克斯时:

  • 纽约

    • 布朗克斯区

    • 布鲁克林

    • 曼哈顿

  • 肯塔基州

    • 阿什兰

    • 巴兹敦

  • 新泽西州

    • 埃塞克斯

    • 米德尔塞克斯

等等......等等...... 因此,除了基础知识之外,我想知道如何自动填充上面的列表并确保结果是所有链接,换句话说,纽约是一个链接,布朗克斯是一个链接,以及列表是我稍后将附加查询字符串的链接...

我正在使用 VB.Net 和 ASP.Net 3.5。 提前致谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岛歌少女 2024-07-21 15:52:18

感谢所有回答或尝试回答的人。
我发现了一个不同但简单的解决方案:

在我的 page_load 中,我调用:

labelwhatever.text = outputRegionAsLinks()

,功能是:

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

这样我可以避免创建 asp 链接按钮或超链接的过载,并直接在我的表单中注入 html 标签,并按照我的意愿定制链接。

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.

○愚か者の日 2024-07-21 15:52:18

如果您想以声明方式执行此操作,请使用嵌套的 Repeater 控件。 外部循环遍历区域表,内部循环遍历区域,当然是基于区域 ID。

执行嵌套重复器的一种简单方法是使用 DataSet 并在两个相关 DataTable 之间创建关系。

这是一个很好的例子: http://jamesewelch.com/2008/03/06/how-to-use-nested-repeater-controls-with-relational-data/

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.com/2008/03/06/how-to-use-nested-repeater-controls-with-relational-data/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文