How to apply groupname to HTML radio buttons in asp.net?
Can anyone please tell about how to apply group name to html (input) radio button controls so that i can select any one of the available radio buttons?
I have input radios in a table. Each row contains two radios as follows. I want to select one from each row. But i am able to select only one radio button amongst 开发者_运维知识库all radio buttons present on all rows.
<input name="radiobutton" type="radio" value="radiobutton" />Option1
<input name="radiobutton" type="radio" value="radiobutton" />Option2
What change i have to make to select one radio button on each row?
Thanks, ~kaps
As far as I know, radiobuttons in HTML do not have group names. Their HTML "name" attribute is the group name.
It is important to verify that each radiobutton has a unique "value" attribute. Otherwise there is no way to tell which of the duplicate values was selected:
<input name="radiobutton" type="radio" value="radiobutton1" />Option1
<input name="radiobutton" type="radio" value="radiobutton2" />Option2
This example lets you choose only one radio button per table row. You have to give all radio buttons the same Name= to create a mutually exclusive group of them.
<form>
<table>
<tr><td>
<!-- Can choose only one of these two. -->
<input name="group1" type="radio" value="1a" />Option1
<input name="group1" type="radio" value="1b" />Option2
</td></tr>
<tr><td>
<!-- Can choose only one of these two. -->
<input name="group2" type="radio" value="2a" />Option1
<input name="group2" type="radio" value="2b" />Option2
</td></tr>
</table>
</form>
GroupName to HTML radio buttons in asp.net
https://www.javatpoint.com/asp-net-radiobutton
<form id="form1" runat="server">
<table>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Gender"></asp:Label>
</td>
<td>
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="gender" Text="Male" />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="gender" Text="Female" />
</td>
</tr>
</table>
</form>
After Rendering from asp.net control tag to html
<form method="post" action="./WebControlsASPX.aspx" id="form1">
<table>
<tr>
<td>
<span id="Label1">Gender</span>
</td>
<td>
<input id="RadioButton1" type="radio" name="gender" value="RadioButton1" /><label for="RadioButton1">Male</label>
<input id="RadioButton2" type="radio" name="gender" value="RadioButton2" /><label for="RadioButton2">Female</label>
</td>
</tr>
</table>
</form>
精彩评论