The RadioButtonList control represents a list control that encapsulates a set of radio button controls.
You can add radio buttons to a Web page using two types of ASP.net controls: individual RadioButton controls or one RadioButtonList control. Both types of controls allow users to choose from a group of mutually exclusive predefined options. With these controls, you can define any number of radio buttons with labels and arrange them horizontally or vertically.
First, Common properties
Property |
value |
function |
RepeatDirection |
horizontal| Vertical |
Layout direction of item: Horizontal Direction | vertical Wind |
RepeatLayout |
table| Flow |
Show Way: Table | streamline |
Selected |
true| Falsee |
is a selected state |
Second, the Code demonstration
Front desk radiobuttonlist.aspx
Copy Code code as follows:
<%@ Page language= "C #" autoeventwireup= "true" codefile= "RadioButtonList.aspx.cs" inherits= "Webcontrols_" RadioButtonList "%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title></title>
<body>
<form id= "Form1" runat= "Server" >
<div>
Please select not: <asp:radiobuttonlist
Id= "Radlsex" runat= "server" repeatdirection= "horizontal" repeatlayout= "Flow" >
<asp:listitem selected= "True" > Male </asp:ListItem>
<asp:ListItem> Women </asp:ListItem>
</asp:RadioButtonList>
<br/>
<asp:button id= "btnsubmit" runat= "Server" text= "Submit" onclick= "btnSubmit_Click"/>
The sex you choose is: <asp:label id= "lblstate" runat= "Server" ></asp:Label>
</div>
</form>
</body>
Backstage RadioButtonList.aspx.cs
Copy Code code as follows:
Using System;
Using System.Collections.Generic;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
public partial class WebControls_RadioButtonList:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
}
protected void btnSubmit_Click (object sender, EventArgs e)
{
Lblstate.text = Radlsex.selectedvalue;
}
}