转发器中的单选按钮出现问题。我有一个表,如
type 1 type 2 type 3 name 1 radioBtn radioBtn radioBtn name 2 radioBtn radioBtn radioBtn
我的目标是能够只选择一种类型的名称......但我不能。它允许每行选择多个,我无法取消选择它。
<asp:Repeater ID="rpt" runat="server" >
<HeaderTemplate>
<table class="table">
<thead>
<tr>
<th style="border: none;"></th>
<th style="border: none; text-align: center;" >
Type 1
</th>
<th style="border: none; text-align: center;">
Type 2</th>
<th style="border: none; text-align: center;">
Type 3</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="border: none;">
<td style="border: none">
<asp:Label runat="server" ID="lblName" Text='<%# Eval("Name") %>'></asp:Label>
</td>
<td style="border: none; ">
<asp:RadioButton runat="server" OnDataBinding="check_OnDataBinding" GroupName="rdGroupOfMine" style=" margin-left:45%" ID="check" CssClass="radio" />
</td>
<td style="border: none; ">
<asp:RadioButton runat="server" OnDataBinding="check_OnDataBinding" GroupName="rdGroupOfMine1" style=" margin-left:45%" ID="check2" CssClass="radio" />
</td>
<td style="border: none; ">
<asp:RadioButton runat="server" OnDataBinding="check_OnDataBinding" GroupName="rdGroupOfMine2" style=" margin-left:45%" ID="check3" CssClass="radio" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</Table>
</FooterTemplate>
</asp:Repeater>
任何人都可以帮助我吗?我尝试使用此代码。但它会对所有单选按钮起作用,即每当我选择了一个按钮时,它会删除之前的选择,无论你在哪里。
JAVASCRIPT
function SetSingleRadioButton(nameregex, current) {
alert(nameregex);
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 (elm != current)
{
elm.checked = false;
}
}
}
current.checked = true;
}
C#
protected void check_OnDataBinding(object sender, EventArgs e)
{
RadioButton rd = (RadioButton) sender;
string script = "SetSingleRadioButton('" + rd.ClientID + "',this)";
rd.Attributes.Add("onclick", script);
}
有人可以帮我取消选择行吗?