今天项目需要在repeater中放置一个radiobutton,结果发现groupname根本不起作用,
因为放在repeater等数据控件中的服务器端控件,会在生成的时候自动加前缀保证id是unique的,
baidu,google找了好久,原来这是很久很久以前的一个BUG,只是到现在还没修复。。。
http://support.microsoft.com/default.aspx?scid=kb;EN-US;316495

最后终于找到一个英文的解决方案,
http://www.codeasp.net/blogs/Shaitender/microsoft-net/150/radio-button-single-selection-in-reapter-datalist
-----------------------------原文分割线------------------------
I have spent lot of time searching on google and fixing the single selection of radion buttion problem in datalist/reapter. Here is the code to use radio buttion inside repeater and datalist . Problem we face while using radio buttion in datalist that we are not able to check single radio buttion,if we use it simply it will act like check box. So, over come this problem of mutiple selection.We can use the following javascript for single selection.

Here is the example code snippets :
<asp:Repeater ID="rptTest" runat="server" OnItemDataBound="rptTest _ItemDataBound">
         <HeaderTemplate>
            Select Radio buttion
         </HeaderTemplate>
 <ItemTemplate>
            <asp:RadioButton ID="radTest" runat="server" />                            
</ItemTemplate>
</
asp:Repeater>

On Repeater ItemDataBound event :-
protected void rptTest_ItemDataBound(object sender, RepeaterItemEventArgs e)     
   {
    if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
                return;
            RadioButton rdo = (RadioButton)e.Item.FindControl("radTest");        
            string script = "SetSingleRadioButton('rptTes  t.*Test',this)";
            rdo.Attributes.Add("onclick", script);
    }

Java Script for Unique Radio Button :-
<script type="text/javascript">
    function SetSingleRadioButton(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;
    }
Hope it Helps …Thanks

---------------------------------OVER------------------
问题顺利解决,
总的来说就是用js和正则表达式,匹配前后缀符合的radio类型,取消全部选中,设置当前选中。。。



原文连接: http://blog.163.com/terry_012/blog/static/4693744920101175225366/