微软已证实这是一个Bug,要解决此问题,首先将下面的JavasScript代码放入前台文件:
function SetUniqueRadioButton(nameregex, current)
{
re = new RegExp(nameregex);
for(i = 0; i < document.forms[0].elements.length; i++)
{
elm = document.forms[0].elements[i]
if (elm.type == 'radio')
{
if (re.test(elm.name))
{
elm.checked = false;
}
}
}
current.checked = true;
}
然后将下面的VB.net代码加入后台文件:
Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim rdo As RadioButton = CType(e.Item.FindControl("RadioButton1"), RadioButton)
Dim script As String = "SetUniqueRadioButton('DataList1.*RadioGroup',this)"
rdo.Attributes.Add("onclick", script)
End If
End Sub
这样就大功告成了。注意这里假设你的DataList控件ID为DataList1,RadioButton控件ID为RadioButton1,GroupName为RadioGroup,请按照你自己的实际情况修改。
参考链接:http://www.codeguru.com/csharp/csharp/cs_controls/custom/article.php/c12371/