Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to get multiple Radiobutton in mvc4
Posted
Comments
F-ES Sitecore 14-Dec-15 8:36am    
There is only one radio button selected by design. You might need to clarify what you're asking.

You have only have one radio button per container or group selected at any one time.

To have more than one radiobutton selected then you must group the radio buttons - e.g. put the radiobuttons for one option into a Panel control, and for another option into another Panel control.

You can also utilise the GroupName property for the RadioButtons - this way even if they are in the same container they will still work as a group e.g.
ASP.NET
<asp:Panel ID="Panel1" runat="server">
    <asp:RadioButton ID="RadioButton1" runat="server" GroupName="Group1" />
    <asp:RadioButton ID="RadioButton2" runat="server" GroupName="Group1" />
    <asp:RadioButton ID="RadioButton3" runat="server" GroupName="Group2" />
    <asp:RadioButton ID="RadioButton4" runat="server" GroupName="Group2" />
</asp:Panel>

If however, you want to have multiple selections within the group then use CheckBoxes or a CheckBoxList
 
Share this answer
 
v2
You can only get the value of selected radio group (which the name property are the same).

Or you want to get selected radios from different rows :
Here an example that treat table in each comlumn you have a group of radio:

This code work :

Code JavScript :
C#
<script>
 function getChecklistItems() {
var result = $("tr > td > input:radio:checked").get();
var columns = $.map(result, function (element) {
return $(element).attr("value");
});
alert("selected rows are : " + columns.join(","));
//after you can use ajax code to send comumns as string and in server part you can split it to get array
                                        }
</script>


Code HTMl :
<table>
<tr><td><input type="radio" name="group1" value="Male"/>Male</td><td><input type="radio" name="group1" value="Female" />Female</td></tr>
<tr><td><input type="radio" name="group2" value="yes"/>yes</td><td><input type="radio" name="group2" value="no" />no</td></tr>
<tr><td><input type="button" value="Show Result" onclick="getChecklistItems()"/></td><td></td></tr>
</table>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900