gpt4 book ai didi

asp.net - ListItem 附加自定义值

转载 作者:行者123 更新时间:2023-12-04 04:34:03 24 4
gpt4 key购买 nike

我在asp.net中使用下拉列表,它有代表下拉列表项目的ListItem集合,每个ListItem只有两个字段来保存数据,Value和Text字段,但这些还不够我想保存更多数据对于每个项目。让我们在附加字段中说 Text1 和 Text2,但同时我想保留下拉列表的 DataBind() 方法的相同行为。

最佳答案

当然,您可以使用 Attributes 集合:

ListItem li = new ListItem("myText", "myID");
li.Attributes.Add("data-x", "xx");
dropdown.Items.Add(li);

这将为您提供以下 HTML:
<select name="dropdown" id="dropdown">
<option value="myID" data-x="xx">myText</option>
</select>

我建议您使用“data-”作为自定义属性的前缀: http://html5doctor.com/html5-custom-data-attributes/

关于asp.net - ListItem 附加自定义值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20065538/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com