RSS

Search Engine

Wednesday, May 19, 2010

ASP.Net RadioButton Checked And GroupName Property

The Checked property of ASP.Net RadioButton control enables you to get or set the selected state of radiobutton. You can also set the checked property of radio button control dynamically using server code or manually when user clicks the radiobutton control to change its selected state. The checked property of ASP.Net radiobutton control accepts the Boolean value to set its state. It also returns the Boolean value to represent the state of the radio button placed on the web page. When user clicks the radiobutton control to set its state as checked then it returns "true" and when user selects other radio button from the same group then it sets the first radio button to un-checked state and clicked radio button to checked state.

Sample Code for ASP.Net RadioButton Checked Property

source code for RadioButton control we have declared the Checked property as "true" for the first radio button. It will render the radio button with checked state initially. To create the mutually exclusive set of choices we have used the GroupName property of radio buttons assigned with same value as "group1". It will provide the functionality to select the single radio button within the same group of radio buttons.

C# Code:

protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "RadioButton1.Checked = " + RadioButton1.Checked.ToString() + "
";
Label1.Text += "RadioButton2.Checked = " + RadioButton2.Checked.ToString();
}

We have also used the Button Control to get the value of Checked property of radio button controls. In the attached click event handler of Button control we have retrieved the values to display them on the web page with the help of Label control.

0 comments:

Post a Comment