【问题标题】:Multi-value dropdownlist多值下拉列表
【发布时间】:2010-09-07 05:14:15
【问题描述】:

目前在asp.net中,DropDownList中的ListItem只能有一个值。但是我希望我可以:

<MultiValueDropDownList id="ddl" runat="server" />
ddl.Items.Add(new MultiValueListItem { Text="text", DBValue="db", EngineValue=1 });
var dbValue = ddl.SelectedItem.DBValue;

我要做的是继承DropDownList和ListItem。大家有没有更好的解决方案?

[关闭]

最后我决定选择一种偷懒的方式。将值存储在 ListItem.Attributes 中。并使用 DropDownList 的扩展方法来帮助获取值的集合。感谢您的帮助!

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    看看这是否有帮助:

    EasyListBox

    How to display multi-column in ASP Dropdown List?

    asp.net : an alternative to multi-column DropDownList Gridview within dropdownlist / combobox (using the Ajax DropDownExtender)

    编辑:

    你不能从ListItem继承。

    看看为什么:Extending ASP.NET DropDownList

    最好的解决方案是将值存储在 ListItem.Attributes 中。

    【讨论】:

    • 这个解决方案可以解决这个问题,但是我真的希望这个团队中的其他开发人员编写“漂亮的代码”。将值连接成一个字符串不是很艺术,不是吗?
    • 啊哈~终于有了相同的解决方案:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-04
    • 1970-01-01
    • 1970-01-01
    • 2017-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多