RadioButton. GroupName in Repeater is invalid, repeaterbutton
Recently, when I was working on a project, I had to display multiple radiobutton In the repeater and implement the Single-choice function. As a result, GroupName is added naturally, but this is not the case, when radiobutton in repeater is displayed to the page, the name will automatically add the repeater id, sequence ct100, and radiobutton id, which directly leads to the failure of GroupName. I have searched for many methods on the Internet, but they are not applicable, such as using <input type = radio> and radiobuttonlist. However, since radiobutton is used, I am too reluctant to change it, the following is my code implementation:
Page
1 <table> 2 <tr> 3 <asp:Repeater runat="server" ID="repbgs"> 4 <ItemTemplate> 5 <td> 6 <asp:RadioButton runat="server" ID="rdo1" Text='<%# Eval("name") %>' /> 7 </td> 8 </ItemTemplate> 9 </asp:Repeater>10 </tr>11 </table>
The backend will not be displayed in a binding process, and jQuery
1 $(':input:radio').click(function () {2 if ($(this).is(':checked')) {3 $(this).is(':checked');4 $(this).parents().siblings().children().removeAttr("checked");5 }6 });
The above is my simple implementation
How does radiobutton in the subrepeater nested by repeater implement single choice?
Add radiobutton
Onclick = "selectSingleRadio (this );"
Function selectSingleRadio (rbtn ){
Var radio = document. getElementsByTagName ("radio ");
Var arrAll = document. all;
For (I = 0; I <arrAll. length; I ++ ){
If (arrAll [I]. type = "radio "){
ArrAll [I]. checked = false;
}
}
Rbtn. checked = true;
}
How can a repeater be a group with RadioButton?
I 've been thinking about it for a long time, just as you thought it was a repeater...
Currently, repeater does not have a method similar to that provided by gridView that can operate a single row.
As you said, I thought of two methods.
The page uses the ordinary html Tag radio, and the id does not need to be specified. Only the name is specified.
<Input type = "radio" name = "rbtn _ <% # Container. itemIndex %> "value =" <% # Eval ("Id") % >_< % # value of the database you want to insert %> "/>
<Input type = "radio" name = "rbtn _ <% # Container. itemIndex %> "value =" <% # Eval ("Id") % >_< % # value of the database you want to insert %> "/>
When you submit a form, use the for loop to spell out the radio name, then obtain the value, split the value to get the ID and the value you want to insert into the database, and directly update the database using an SQL statement.
The second method is to use AJAX, that is, bind the onclick event on the radio control, upload the value to the background for segmentation, asynchronously update, and finally modify the selected radio in js.
Two Methods: I recommend the second one and hope to adopt
In addition, the webmaster group has products to buy, Which is cheap and guaranteed.