RadioButtonList Selected Item Value
RadioButtonList is an asp.net list web server control that provides a single selection radio button group.
the following asp.net c# example code demonstrate us how can we get selected item's value from a radiobuttonlist
server control.
RadioButtonList contains ListItem objects. ListItem object's Text property get or set the text displayed in web browser. and the Value property set the value associated with the ListItem.
RadioButtonList SelectedItem property get the selected item from the list. so we can programmatically get the selected item's value in a radiobuttonlist control by accessing SelectedItem.Value property. because SelectedItem returns a ListItem object which is selected in radiobuttonlist server control.
RadioButtonList contains ListItem objects. ListItem object's Text property get or set the text displayed in web browser. and the Value property set the value associated with the ListItem.
RadioButtonList SelectedItem property get the selected item from the list. so we can programmatically get the selected item's value in a radiobuttonlist control by accessing SelectedItem.Value property. because SelectedItem returns a ListItem object which is selected in radiobuttonlist server control.
radiobuttonlist-selectedvalue.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
RadioButtonList1.Items.Add(new ListItem("Silver Oriole", "1"));
RadioButtonList1.Items.Add(new ListItem("Hooded Oriole", "2"));
RadioButtonList1.Items.Add(new ListItem("Orange Oriole", "3"));
RadioButtonList1.Items.Add(new ListItem("Baltimore Oriole", "4"));
RadioButtonList1.Items.Add(new ListItem("Streak-backed Oriole", "5"));
}
}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
Label1.Text = "you selected....<br />";
Label1.Text += "item: " + RadioButtonList1.SelectedItem.Text;
Label1.Text += "<br />value: "+RadioButtonList1.SelectedItem.Value;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>asp.net radiobuttonlist selectedvalue</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
asp.net example - radiobuttonlist selectedvalue
</h2>
<hr width="550" align="left" color="Gainsboro" />
<asp:Label
ID="Label1"
runat="server"
Text="select an item from radiobuttonlist...."
Font-Size="Large"
Width="350"
>
</asp:Label>
<br /><br />
<asp:RadioButtonList
ID="RadioButtonList1"
runat="server"
RepeatLayout="Table"
RepeatColumns="2"
AutoPostBack="true"
OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"
>
</asp:RadioButtonList>
</div>
</form>
</body>
</html>

- How to sort DropDownList items in descending order
- How to set default selected items in a ListBox
- How to create a horizontal layout RadioButtonList
- How to check that RadioButtonList has a selected item
- How to set a default selected item in RadioButtonList
- How to perform foreach loop through RadioButtonList items
- How to add different tooltip for RadioButtonList items
- How to add margin between items in a RadioButtonList
- How to set RadioButtonList items vertical alignment
- How to add vertical space between items in a RadioButtonList