Click here to Skip to main content
15,891,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Following strong and frequent advice here in various answers, I wish to use a RadioButton for each row in a table, for a user to select only one row to perform an action on. However, I am using an editor template to generate the table, and each RadioButton has a different name due to the row index being part of the name. Right now I can select all the RadioButtons at once, defeating their object.

How can I group these RadioButtons so that only one at a time can be selected?
Posted
Comments
David_Wimbley 26-May-13 2:16am    
Can you post some code...im being overly lazy and don't feel like trying to re-create your scenario myself.

But off the top of my head you can certainly use JQuery (.each function) and run logic inside your .each function to limit what can be selected by setting the checked attribute to .attr("checked", ""). Are you able/allowed to use Jquery in this scenario?

If you post some code i'd be happy to throw something together.
Brady Kelly 26-May-13 2:30am    
The code would be hard to post, but I can throw a jQuery solution together myself anyway, thanks. I just feel there should be some way to make radio buttons behave like they are supposed to.
Zoltán Zörgő 26-May-13 2:44am    
It is hardly possible due to the fact, that the grouping is performed on html level via the name property. Thus, if you put different names, they will be different groups for the browser. But I am certain you don't need row index in the input name, you could put it in the ID, or in an outer element, where it belongs, thus you would not break the html principles and would have the desired functionality without hacking. They would work as they are supposed to work if you would let them...

1 solution

Hi Brady,

try this Group Radio Button in MVC
 
Share this answer
 
Comments
Brady Kelly 29-May-13 3:56am    
Thanks, this is quite interesting, but it doesn't seem deal with radio buttons with unique index subscripts in their names, as radio buttons in a list editor do.

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