Add ListItem to RadioButtonList
<script language="C#" runat="server">
protected void Page_Load(object o, EventArgs e) {
if(!IsPostBack) {
ListItem item;
item = new ListItem("A", "1");
languageRadioButtonList.Items.Add(item);
item = new ListItem("B", "2");
languageRadioButtonList.Items.Add(item);
item = new ListItem("C", "3");
languageRadioButtonList.Items.Add(item);
}
}
protected void DropDownListSelectionChanged(object o, EventArgs e) {
favoriteLanguage.Text = languageRadioButtonList.SelectedItem.Value;
}
</script>
<form runat="server">
<asp:RadioButtonList
id="languageRadioButtonList"
runat="server"
OnSelectedIndexChanged="DropDownListSelectionChanged" >
</asp:RadioButtonList><br/>
Favorite Language: <b><asp:label runat="server" id="favoriteLanguage" style="color:blue" /></b><br />
<asp:button runat="server" Text="Submit"/>
</form>
Related examples in the same category