.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Series of Radio Buttons in MVC

Posted By:      Posted Date: August 27, 2010    Points: 0   Category :ASP.Net

Hi.  I'm fairly new to MVC and admittedly don't fully understand how data is passed between Views and Controllers.  That said, here is my issue.


I am working with C#.  I have a page which has a list of items.  Each item has a radio button set of three associated with it and there are 15 of these sets on the page.  Thus I have radio1, radio2....radio15, etc.  Each of these has value 0, 1, or 2 upon submit.  I can't seem to understand how to get the information out of these radio button sets from the controller without passing 15 different variables to the post method in the controller which is associated with the view; ie passing Int32 radio1, Int32 radio2,.., Int32 radio15, etc.

I tried using ViewData["radio"+i] in a loop to access the value of each radio button set, but this, apparently can only be used to pass data to the View from the Controller and not the other way around.

Any advice is appreciated.



View Complete Post

More Related Resource Links

Gridview with Radio Buttons

As now, Radio buttons are HTML controls, I am not able to get it on server side. When user select any radio button and press submit, Control will not available at code behind, you can use "e.Item.FindControl" as it is not "runat='server'". I want ID "Primary Key" value for selected radio button. To achive this I took the help of Javascript. I wrote javascript function that sets the values of "Primary Key" in hidden field when user clicks on any radio button. Now when user clicks on Submit button, user can get selected value froim hidden field.

groupBox radio buttons

Hello   On my form, I've got two groupbox's and each group box has two radio buttons. I believe the expected operation, is that if one is checked , the other is not with in the groupbox. How can I make it so only one is checked among the four?

Using ReportViewer for multiple reports by way of radio buttons

 Hi all, Thanks for taking the time to read over my scenario.  I am using one ReportViewer with already established SQL Stored Procedures connected to three report files (*.rdlc).  There are three radio buttons which are to be associated with each report that needs to be displayed in the ReportViewer.  Here is an example if a radio button is selected:ReportViewer1.Reset() Dim rds As Microsoft.Reporting.WebForms.ReportDataSource rds = New Microsoft.Reporting.WebForms.ReportDataSource ReportViewer1.LocalReport.DataSources.Clear() If RadioButtonList1.SelectedIndex = 0 Then rds.DataSourceId = ObjectDataSource1.ID rds.Name = "spEx1" rds.Value = ObjectDataSource1 ReportViewer1.LocalReport.DataSources.Add(rds) ReportViewer1.LocalReport.ReportPath = "Ex1Report.rdlc" ... The ReportViewer works for the first radio button selection but then for the other selection I get the following error: A data source instance has not been supplied for the data source 'spEx1' I'm not sure exactly what is going on or where it's still tied to the first data source.  Any help would be great!  Thank you.

Problem with radio buttons in a repeater


I can use the asp control and find the radio buttun in the code behind when a button is clicked but the user can select multiple buttons, or I can use an html input type radio and be able to select only one button of the group but not find it in the button's click event.  Is there a way to both be able to find the radio button AND have it di what it's supposed to - only allow one to be checked?

Radio Buttons - OnChange


I'm having a time finding out I could not do something simple as :

On the onchange event getting the new selected checkbox, this with jquery.

The checkboxes are located in the following div :

<div id="radio">
                <%= Html.RadioButton("radio1", "Ja", Model.Status == 1 ? true : false) %><label for="radio1">Ja</label> 
                <%= Html.RadioButton("radio2", "Nee", Model.Status == 0 ? true : false) %><label for="radio2">Nee</label> 
                <input type="hidden" id="radioValue" name="radioValue" />

This all located in a form, when I will find out the selected radio on change I will post the form and use the value of the hidden field to know the selected radion button. Nothing realy difficult.

The js code :

$("input[type='radio']", "#radio").change(function(e) {
      // Get the selected radio button


Any help appreciated.

How to find unselected radio buttons using JQuery?


I would like to find which radiobutton group (not individual radiobutton) has not been checked, tried a lot of different ways, no success so far. What I want to do is find validate radiobutton groups and highlight them.

$('input:radio:not(checked')).each(function() {


IE 9 Beta & InfoPath 2007 Form Radio Buttons Not Working



Has anyone else come across the IE9 bug that causes the radio buttons in the InfoPath 2007 forms to stop working (i.e. unselectable)?

Did you find a workaround (other than not to use IE9!)?



Selecting radio buttons in a gridview with dataset from Linq Query


Hi Everyone!

I've got a gridview that will allow clients to edit options they've already entered on another page.  The gridview has three radio buttons in it each with a value of 1,2,3.  The option value in the dataset is 1,2 or 3 respectively.  I would like to have the radiobutton with the corresponding value selected in the gridview so they can see what they previously chose and will then be able to edit, if they wish.

How do I do this? 

Here's my code so far:

Dim clientOption = (From c In dc.ClientOptions _
                                 Where c.clientID = userClientID _
                                 Select New With {c.clientOptionID, _
                                                  c.optionWording, _

            'Now Populate Gridview 1 with set options
            If clientOption Is Nothing Then
                Label1.Text = "There are currently no set options to edit."

                GridView1.DataSource = clientOption
                Label1.Text = "Edit set options."
            End If

            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="F

Radio buttons, a label and an image button show twice inside update panel


I have an update panel with a set of 2 radio buttons, a label and an image button inside of it. There another set of 3 radio buttons that trigger the update panel. I got everything working but now the image button, label and set of 2 radio buttons inside the update panel show up twice when the radio button triggers are selected? Any ideas?

Multiple radio buttons

I'm programming on C#, and I've a groupBox containing multiple radioButtons, Can anyone tell me how can i determine the checked radio button (at any time not at the radioButton checked event)?
Please give an example code.

WPF converter and radio buttons switching from codebehind problem


Hi everybody,


I have an UserControl which has some class as its DataContext. This class implements INotifyPropertyChanged. I have a property on this class, which is an enum binded to RadioButtons throught converter. In UserControl.xaml.cs I have registered a hotkey, that is circling the values of enum and I'm expecting to change the selection of RadioButtons as well. The binding is OK (Mode=TwoWays), notification runs also well, but...


... but: when I have the last RadioButton selected I'm not able to switch with hotkey to the first one.


The enum is binded like this:

<Utils:EnumBooleanConverter x:Key="EnumBooleanConverter"/>
<RadioButton IsChecked="{Binding Path=ActivityType, Converter={StaticResource EnumBooleanCo

ASP.NET, HTML, JavaScript Snippet Support (VS 2010 and .NET 4.0 Series)

This post covers another useful improvement in VS 2010 - HTML/ASP.NET/JavaScript snippet support. Snippets allow you to be more productive within source view by allowing you to create chunks of code and markup that you can quickly apply and use in your application with a minimum of character typing.

Visual Studio has supported the concept of "snippets" for VB and C# in previous releases - but not for HTML, ASP.NET markup and JavaScript. With VS 2010 we now support snippets for these content types as well.

Clean Web.Config Files (VS 2010 and .NET 4.0 Series)

.NET 4 includes a new version of the CLR, and a new .NET 4 specific machine.config file (which is installed side-by-side with the one used by .NET 2, .NET 3 and .NET 3.5).

The new .NET 4 machine.config file now automatically registers all of the ASP.NET tag sections, handlers and modules that we've added over the years, including the functionality for:

.ASP.NET Dynamic Data
.ASP.NET Routing (which can now be used for both ASP.NET WebForms and ASP.NET MVC)
.ASP.NET Chart Control (which now ships built-into ASP.NET V4)
What this means is that when you create a new "Empty ASP.NET application" project in VS 2010, you'll find that the new default application-level web.config file is now clean and simple:

Code Optimized Web Development Profile (VS 2010 and .NET 4.0 Series)

When you first run VS 2010 it prompts you to select an IDE profile to use. The profile you select will configure how tool windows are displayed/docked in the IDE by default and set the default keyboard shortcuts. You can then customize any of these settings by using the Tools->Options menu within the IDE and then override/change them. You can also later reset your profile and pick a different one by choosing the Tools->Import and Export Settings menu command.

VS 2010 and .NET 4 Series

VS 2010 and .NET 4 are the next major releases of our developer tools and framework. Together they contain a ton of new functionality and improvements that I think you'll really like, and which make building applications of all types easier, faster and better. The improvements range from nice small tweaks to major, major enhancements - and can be found across the .NET Framework, the languages, and the IDE.

Problem to group radio button across gridview rows

In general no one can easily group or make a single selection from radio button list inside gridview rows. There are a lot of way to make a single or unique selection from list. Here i want to share how i can address this problem in the most easiest way. Googling the problem most of the cases i saw the grouping in horizontal way. Thats why i tried to group the radio buttons in vertical manner. Let i have a requirement like below:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend