【发布时间】:2014-09-23 19:12:09
【问题描述】:
我有一个数据绑定的 asp.net RadioButtonList。呈现的列表项显然呈现为类型单选、标签和跨度的输入。
当我遍历每个 ListItem 并添加一个 onclick 属性时,它会根据需要将 onclick 属性添加到输入标记。但是当我添加一个自定义属性时,它会将其添加到周围的跨度中。如何在不通过自定义 ControlAdapter 更改 RadioButtonList 的呈现的情况下将其添加到输入标签?我正在使用网站(不是项目)和.net 2.0。提前致谢!
ASP.NET
For Each li As ListItem In Me.rbl.Items
li.Attributes.Add("onclick", "myFunction();")
li.Attributes.Add("myAttribute", "1")
Next
HTML
<table id="ctl00_ContentPlaceHolder1_rbl" border="0">
<tr>
<td><span myAttribute="1"><input id="ctl00_ContentPlaceHolder1_rbl_0" type="radio"
name="ctl00$ContentPlaceHolder1$rbl" value="Choice1" onclick="myFunction();" />
<label for="ctl00_ContentPlaceHolder1_rbl_0">Choice1</label></span></td>
</tr>
</table>
【问题讨论】:
-
谢谢。我看过类似的讨论,但不幸的是,RadioButtonList 项没有 InputAttributes 属性,只有 Attributes 属性。
标签: html asp.net vb.net radiobuttonlist custom-attribute