我正在寻求一个关于我应该如何为客户采取解决方案的明智的意见。
解决方案包括在asp:中继器内使用单选按钮。最初,我选择使用asp:RadioButtonList,但我遇到的问题是,当使用DataSourceID时,它坚持提供文本标签,而我不能用标签标记封装无线电按钮标签,从而阻止我为任何使用触摸屏设备的人提供更大的点击区域。
它呈现如下:
<td>
<input />
<label />
</td>我想要的是:
<td>
<label>
<input />
</label>
</td>我可以通过在标签标签中包装asp:RadioButton来实现上面的使用。但是,找出在GroupName中选择了哪个无线电按钮,这意味着我需要检查每个无线电按钮并检查其检查的属性。不太优雅。
我已经对这个主题做了一些研究,看起来我可以使用CSS来移动asp:RadioButtonList无线电按钮的位置,这样看起来它们就包含在标签中,并移除标签文本。
从asp:RadioButtonList中删除DataSourceID完全删除<label>标记。这样我就可以在每个无线电按钮上插入一个标签。
或者采用简单的方法,删除asp:RadioButtonList,然后迭代每个asp:RadioButton,直到我找到选中的radiobutton。
我所有的“想法”似乎过于复杂,并不特别优雅。有没有人有过类似的经验?
发布于 2015-12-04 11:19:13
我最后使用了RadioButtons,使用了下面的代码。
<td>
<label>
<asp:RadioButton ID="rb1" runat="server" />
</label>
</td>
<td>
<label>
<asp:RadioButton ID="rb2" runat="server" />
</label>
</td>
<td>
<label>
<asp:RadioButton ID="rb3" runat="server" />
</label>
</td>正如我在最初的问题中所说,无线电按钮包含在一个asp:中继器内。为了迭代无线电按钮和每一行表,我使用了以下代码:
For Each item As RepeaterItem In RepeaterName.Items
If item.ItemType <> ListItemType.Header And item.ItemType <> ListItemType.Footer And item.ItemType <> ListItemType.Separator Then
Dim listOfNames() As String = {"rb1", "rb2", "rb3"}
Dim attended As Boolean = False
Dim index As Integer = 0
Do While checked = False
Dim rbAttendanceCode As RadioButton = CType(item.FindControl(listOfNames(index).ToString), RadioButton)
If rbAttendanceCode.Checked Then
'Do whatever you want with the checked radiobutton
'set the flag as true so we stop looping through the radio buttons.
checked = True
End If
index += 1
Loop
End If
Next希望人们发现这是有用的。
https://stackoverflow.com/questions/34019809
复制相似问题