.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

Set radio-button selection from model's property

Posted By:      Posted Date: October 10, 2010    Points: 0   Category :ASP.Net

I got 3 radion-buttons on the view called:

- Taxi

- Train

- Bus

The model passed has a property called "Transport" of type String.

In the action, if I set the property as 'Train', then the view should set the radio-button 'Train' checked.



model.Transport = "Train";

How do I do that in the view to make the radio-button Train checked?

View Complete Post

More Related Resource Links

Set radio button as checked depends on the model property value


I got 3 radio-buttons:

<input type="radio" name"transport" value="taxi" checked /> Taxi <br />

<input type="radio" name"transport" value="train" /> Train <br />

<input type="radio" name"transport" value="bus" /> Bus <br />

I tried this but got error:

<input type="radio" name"transport" value="bus" <%: if (Model.Transport == "bus" ) { %> checked <:% } %>/> Bus <br />

The error was

CS1525: Invalid expression term 'if'

Any idea?

Maintain HTML Radio Button Selection Inside GridView After Postback

Long time ago I wrote an article about getting the value of the selected RadioButtons inside the GridView control. The code did not addresssed the postback issue which means that the selected radio button was cleared after the postback occurs.

XML Radio Button Selection Issue


Hi All,

I used some code i found on the internet and a little of my own to come up with a custom radio-button that will add a list field to the querystring as a parameter. This code seems to work fine when i stick it in a dataview in its own column, but SharePoint Designer does not seem to like my closing tag "</input>" which will lead SharePoint Designer to occasionally try to fix the code itself, which actually breaks it. I'm not an XML expert by any means, so if anyone could please tell me why the code doesnt seem to be XML certified, i would really appreciate it. Code below:

<input type="radio" value="{@TID}" name="radioMain">

asp.net Radio button grouping property is not working



Iam developing a custom server control  of radiobuttton. it is working fine with the all the properties i wrapped  except the grouping . somehow the grouping is not working .

  // this is my class.
 public class TngRadioButton : CompositeControl


// this is my groupname property

[ DefaultValue(""), Themeable(false) ]
        public virtual string GroupName
                string str = (string)this.ViewState["GroupName"];
                if (str != null)
                    return str;
                return string.Empty;
                this.ViewState["GroupName"] = value;


Please  help me in this resolution.




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:

A Simple and Extensible Radio Button Style GridView

The GridView is one of the significant controls in ASP.NET 2.0 and later versions. No doubt it reduces a lot of work time. However, customizing the GridView control is not an easy task. For example, it's hard to add a radio button column to the GridView. This article demonstrates the reason why a radio button column cannot act as normal and how to create a simple and extensible radio button GridView.

Editable Gridview with Textbox, CheckBox, Radio Button and DropDown List

This is an example of an editable gridview containing different ASP.NET controls. When user wants to edit values in gridview, she/he can use these controls to edit existing values in Gridview Edit Mode.

Using the Code

Radio Button Event

Here I have explained the events of radio button with javascript.
Let me explain the scenarion first,
We are having two radio button say radioobtn1 and radiobtn2. If I click on the button 1 then I need to show one DIVor FORM. same as when I click on radiobtn 2. I have given the code for the above scenarion.

Select only one radio button in a datagrid


I have been frantically searching for help to select only one radio button in datagrid and deselect the other when a new button is clicked.

I do not want to use javascript. Can someone help me on this?

Model Display Property On View


How can I show display property of Model on View.


public class Model
        [DisplayName("First Name")]
        public string FirstName { get; set; }
        <div>FirstName</div><---Here I want to show Dispaly name
        <div><%= Html.Encode(Model.FirstName) %></div>

Gridview radio button

I am making an online train reservation system. I want to create a fare table (as seen in the link ) that will display fare of different classes based on the user selection of route. The fares should provide a radio button that will allow users to select which fare they would want to purchase. I am having trouble on how to show fares of the same schedule of different classes. I want to create something like the Eurostar fare tables. 

Windows Workflow : Activity Binding Properties Window Ellipses button not visible for one property

I have created a custom activity, when I am using this activity in workflow designer I am not getting the ellipsis button to select a property.  I am getting the ellipses button for first property LongValue while not getting the option for "NavigationUrl" property. This is the code for my custom activity. public partial class SetLongAsResult: Activity {         public SetLongAsResult() { InitializeComponent(); }         public static DependencyProperty LongValueProperty = DependencyProperty.Register("LongValue", typeof(long), typeof(SetLongAsResult));           public static DependencyProperty NavigationUrlProperty = DependencyProperty.Register("NavigationUrl", typeof(string), typeof(SetLongAsResult));           [Description("long value to be returned")]         [Category("Set Result Data")]         [BrowsableAttribute(true)]         [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]         public long LongValue         {             get             {         

Selecting One Radio Button In A GridView

Hello, how do I add a RadioButton column to a gridview so that only one button is selectable? Here is what I have now. <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:RadioButton ID="RadioButton2" runat="server" /> </ItemTemplate> </asp:TemplateField> <asp:HyperLinkField DataTextField="Text" DataNavigateUrlFields="NavigateURL" /> </Columns> </asp:GridView>  

Radio button and Checkbox don't work in Opera

I have a webform with 2 radio buttons and 1 checkbox. These work in IE and FireFox, but theye never get checked in Opera. Is this some problem with Opera or with my checbox/radio button?ThanksI have the following code:<asp:CheckBox ID="ckTermsNConditions" runat="server" Checked="false" /><asp:RadioButtonList ID="rblRegistrationType" runat="server" CellPadding="2" CellSpacing="2"  >                        <asp:ListItem Value="Vendor" Selected="False">How to</asp:ListItem>                        <asp:ListItem Value="Consultant" Selected="False">Feedback</asp:ListItem>                        <asp:ListItem Value="User" Selected="False">Question</asp:ListItem></asp:RadioButtonList>

set the Report URL property to a specific report dynamically based on the selection in the list.

Hi I want to use  embedding the Report Viewer Web Part in a Web page, and I know we  should set the Report URL property to a specific report. but  is there a way by which we can set the url  dynamically based on the selection of the report  from  the list How can I customize this  feature Any Help on this is appreciated. Thanks

RadioButtonList without the Radio Button Circle?

basically, i just want the RadioButtonList without the radio button on it, i will code the rbl so that selected items have a different background color and make it look more professional, the radio buttons themselves i want to be able to get rid of in terms of apperance... if you know of any way to do it, please do let me know!

Data Annotation not triggering the client side validation when used on an overriden model property

Hi all, This is a saga from a post that was recently answered:http://forums.asp.net/t/1598187.aspxMy main problem is the lack of client side validation when we use a child model class, the server side validation works like a charm whether you use the virtual/override solution or the new attribute on the child class with the getter and setter linking the property to the base class's one.The client side validation does not work with none of the solutions presented below.This is a sample code of the first solution: [Serializable] public class DateViewModel { ... [Display(typeof(App_GlobalResources.Messages), "Date_Year")] public virtual int? Year { get; set; } ... } [Serializable] public class BirthDateViewModel : DateViewModel { ... [Display(typeof(App_GlobalResources.Messages), "Date_Year")] [YearRange(ErrorMessageResourceType = typeof(App_GlobalResources.Messages), ErrorMessageResourceName = "Validation_Range")] public override int? Year { get; set; } ... } This is a code sample of the second solution : [Serializable] public class DateViewModel { ... [Display(typeof(App_GlobalResources.Messages), "Date_Year")] public int? Year { get; set; } ... } [Serializable] public class BirthDateViewModel : DateViewMod
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