【问题标题】:Using a C# asp.net dropdownlist instead of HTML ul list使用 C# asp.net 下拉列表而不是 HTML ul 列表
【发布时间】:2023-03-05 01:08:01
【问题描述】:

我正在使用 html 列表来帮助使用传单在地图上查找特定区域。这是一个普通的 html ul 列表,但在每行之间插入了一个标签。我还包含了数据位置和缩放属性,以精确定位地图上的特定位置。

HTML 列表:

<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
    <li role="presentation"><a href="#" data-zoom="6" data-position="57.3666,   -25.0008"> Orginal map.....</a></li>
    <li role="presentation"><a href="#" data-zoom="12" data-position="54.3666,-9.0"> Irish Continental Shelf</a></li>
    <li role="presentation"><a href="#" data-zoom="12" data-position="53.27,-9.91"> Irish Exclusive Economic Zone</a></li>
    <li role="presentation"><a href="#" data-zoom="12" data-position="51.74404,-10.12931"> Irish Territorial Sea</a></li>
    <li role="presentation"><a href="#" data-zoom="12" data-position="53.35547,-6.17153"> Irish Contiguous Zone</a></li>
</ul>

ASP 下拉列表:

<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true" BackColor="BurlyWood">  
    <asp:ListItem  Value="Navigation ToolBox Control">Irish Continental Shelf</asp:ListItem>  
    <asp:ListItem Value="Standard ToolBox Control">Irish Exclusive Economic Zone</asp:ListItem>  
    <asp:ListItem Value="Data ToolBox Control"> Irish Territorial Sea</asp:ListItem>  
    <asp:ListItem Value="Login ToolBox Control">Irish Contiguous Zone</asp:ListItem>  
</asp:DropDownList>

现在我想使用 asp:Dropdown 列表,但 c# sharp 不允许任何标签。这意味着我无法使用数据位置或缩放链接到地图上的特定点。

在 C# 中有没有办法整合这个特性?

【问题讨论】:

  • “在每行之间插入标签”是什么意思......?什么标签……?
  • 道歉我的意思是超链接的锚标签

标签: c# html asp.net leaflet


【解决方案1】:

你可以使用这样的东西

ListItem a1 = new ListItem("Irish Continental Shelf");
        a1.Attributes["data-position"] ="12,54";
        a1.Attributes["test2"] = "2";
        DropDownList1.Items.Add(a1);

【讨论】:

    【解决方案2】:

    据我所知,您对列表项的属性非常感兴趣。在这种情况下,根据this QnA,您应该使用InputAttributes 属性。

    myDropDownList.InputAttributes.Add(...)
    myListItem.InputAttributes.Add(...)
    

    【讨论】:

    • 你先尝试过这个吗? InputAttributes似乎是一个 CheckBox-only 属性。
    • 很遗憾,目前没有编译器或项目。似乎该属性通常在 ASP.NET 控件上命名为Attributes
    • 好吧,我试过了,但 DropDownList 和 ListItem 类都没有InputAttributesAttributes 仅指控件本身的属性,在开始标记内,如id="foo"style="foo"。所以Attributes 也不正确。而且由于 ListItem 似乎也没有 Controls 属性,所以我不确定什么会起作用(不过,应该有一种方法......)。
    • ListItems 确实有一个Attributes,可以看到here。因此,通过赋予列表项标识,也可以为它们操作属性。
    猜你喜欢
    • 2015-06-14
    • 2013-02-02
    • 1970-01-01
    • 1970-01-01
    • 2011-08-27
    • 2016-05-22
    • 2010-09-18
    • 2016-08-03
    • 2011-10-29
    相关资源
    最近更新 更多