ASP. NET radio button control RadioButton commonly used properties and methods introduction

  • 2020-12-10 00:40:57
  • OfStack

1. Common properties:

(1) Checked property: It is used to set or return whether the radio button is selected. The value when selected is true, and the value when not selected is false.

(2) AutoCheck attribute: If the AutoCheck attribute is set to true (the default), all other radio buttons in the group will be automatically cleared when the radio button is selected. For general users, the default value (true) is used instead of changing this property.

(3) Appearance property: Used to get or set the appearance of radio button control. When it is Appearance.Button, it makes the radio button look like the command button 1: when selected, it looks as if it has been pressed. When the value is ES17en.Normal, it is the default radio button appearance.

(4) Text property: It is used to set or return the text displayed in the radio button control. This property can also contain access keys, i.e. & "

The letter of a symbol so that the user can select the control by pressing both the Alt key and the access key.


2. Common Events:

(1) Click event: When the radio button is clicked, the Checked attribute value of the radio button is set to true, and the Click event occurs simultaneously.

(2) CheckedChanged event: When the value of Checked attribute changes, CheckedChanged event will be triggered.

radiobutton in WPF may be a little different from Web and does not have attributes like group. When using, radiobutton from the same group is directly put into one groupBox or panel, and they automatically become one group. There are two methods to determine which one is selected during use:

The first method:


foreach (Control ctrl in groupBox1.Controls)
{
 if (ctrl is RadioButton)
 {
  if (((RadioButton)ctrl).Checked )
  {
   // Add the actions you need 
  }
 }
} 

Method 2: Add events to each radiobutton

private void radioButton_CheckedChanged(object sender, EventArgs e)
{
 RadioButton rb=(RadioButton) sender;
 if (rb.Checked)
 {
     // Add the actions you need                      
    }
}



Related articles: