我在asp.net中使用dropdownlist,它有代表下拉列表项目的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/ http://html5doctor.com/html5-custom-data-attributes/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)