RadioButtonList web server control
ASP.NET RadioButtonList control enables the user to select an item from
the list. RadioButtonList supports data binding programmatically from the
database. We can also populate it manually by inputting a list of items inside
the RadioButtonList tag. RadioButtonList is a single selection radio button
group. RadioButtonList has an item collection. We can determine which item is
selected by testing its SelectedItem property.
We can change RadioButtonList design by setting up its various property as like BackColor, BorderColor, BorderStyle, BorderWidth, CellPadding, CellSpacing, CssClass, Font-Bold, Font-Italic, Font-Names, Font-Overline, Font-Size, etc. there are more three properties RepeatColumns, RepeatDirection, and RepeatLayout which help you to place list item vertically or horizontally.
RadioButtonList has standard AutoPostBack property. As with other list control, RadioButtonList has an excellent event SelectedIndexChanged. So that when someone selects an item it automatically posts back to the page and we can determine programmatically which item is selected now. For that, we need to set the AutoPostBack property value to true and set up a SelectedIndexChanged event. DataSourceID, DataTextField, and DataValueField property help you to data bind RadioButtonList with the database. RadioButtonList also supports theme and skin.
In this example we demonstrate a very simple example of RadioButtonList. Select an item from RadioButtonList and submit the form by clicking Button control. You will get which item is selected from RadioButtonList.
We can change RadioButtonList design by setting up its various property as like BackColor, BorderColor, BorderStyle, BorderWidth, CellPadding, CellSpacing, CssClass, Font-Bold, Font-Italic, Font-Names, Font-Overline, Font-Size, etc. there are more three properties RepeatColumns, RepeatDirection, and RepeatLayout which help you to place list item vertically or horizontally.
RadioButtonList has standard AutoPostBack property. As with other list control, RadioButtonList has an excellent event SelectedIndexChanged. So that when someone selects an item it automatically posts back to the page and we can determine programmatically which item is selected now. For that, we need to set the AutoPostBack property value to true and set up a SelectedIndexChanged event. DataSourceID, DataTextField, and DataValueField property help you to data bind RadioButtonList with the database. RadioButtonList also supports theme and skin.
In this example we demonstrate a very simple example of RadioButtonList. Select an item from RadioButtonList and submit the form by clicking Button control. You will get which item is selected from RadioButtonList.
RadioButtonListHowToUse.aspx
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
Label1.Text ="You Selected Collection: " + RadioButtonList1.SelectedItem.ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>RadioButtonList example: how to use RadioButtonList control in asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Font-Size="Large" ForeColor="Crimson"></asp:Label>
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem>ColdFusion</asp:ListItem>
<asp:ListItem>Asp.Net</asp:ListItem>
<asp:ListItem>PHP</asp:ListItem>
</asp:RadioButtonList>
<br />
<asp:Button ID="Button1" runat="server" Text="Show Selected Software" OnClick="Button1_Click" />
<hr />
</div>
</form>
</body>
</html>