RadioButtonList control example
RadioButtonList is an ASP.NET list web server control. RadioButtonList
control renders a group of radio button controls where each radio button
shares the same group name. RadioButtonList control encapsulates a radio
group. RadioButtonList control each ListItem object is renders a single radio
button control.
RadioButtonList control's items exist in an items collection. So we can manage (edit, insert, and delete) RadioButtonList item collection by the .NET framework's Collection Class methods and properties.
RadioButtonList control has many built-in properties to design and style the control itself such as BackColor, ForeColor, CssClass, etc. We also can customize its items level style by core CSS style such each different colors for different items.
RadioButtonList control's AutoPostBack property and SelectedIndexChanged event allow us to quickly get the user's item selection after each time the RadioButtonList selection has changed.
In the following example code, we populated a RadioButtonList control with items by declarative syntax in the tag section. We also keep the AutoPostBack property value to 'True' and write an event handler for its SelectedIndexChanged event.
So when users change the RadioButtonList item selection we caught the selection on the SelectedIndexChanged event handler section and display an image on the web page which is specified by RadioButtonList present selected item.
RadioButtonList control's items exist in an items collection. So we can manage (edit, insert, and delete) RadioButtonList item collection by the .NET framework's Collection Class methods and properties.
RadioButtonList control has many built-in properties to design and style the control itself such as BackColor, ForeColor, CssClass, etc. We also can customize its items level style by core CSS style such each different colors for different items.
RadioButtonList control's AutoPostBack property and SelectedIndexChanged event allow us to quickly get the user's item selection after each time the RadioButtonList selection has changed.
In the following example code, we populated a RadioButtonList control with items by declarative syntax in the tag section. We also keep the AutoPostBack property value to 'True' and write an event handler for its SelectedIndexChanged event.
So when users change the RadioButtonList item selection we caught the selection on the SelectedIndexChanged event handler section and display an image on the web page which is specified by RadioButtonList present selected item.
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void RadioButtonList1_SelectedIndexChanged(object sender, System.EventArgs e) {
Image1.ImageUrl = "Images/" + RadioButtonList1.SelectedItem.Text.ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>RadioButtonList simple example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Image ID="Image1" runat="server" />
<br />
<asp:Label ID="Label1" runat="server" Text="Select for view image"></asp:Label>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal" RepeatColumns="2" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem>ScotlandFlower.jpg</asp:ListItem>
<asp:ListItem>ArtificialOrchid.jpg</asp:ListItem>
<asp:ListItem>CacaoFlower.jpg</asp:ListItem>
<asp:ListItem>Flower.jpg</asp:ListItem>
</asp:RadioButtonList>
</div>
</form>
</body>
</html>