A RadioButtonList can be used to select 1 option within several options. The item "Pizza with egg" is selected by default.
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Selected="True">Pizza with egg</asp:ListItem>
<asp:ListItem>Pizza with tuna </asp:ListItem>
<asp:ListItem>Pizza with ham</asp:ListItem>
Set selected item from Database
If you load Data from a database you sometimes want to select a certain item based on the value in the DB.
You can do so by doing the following:
string pizzaOptionFromDB = someCode.getPizzaFromDB(); // DB returns "Pizza with tuna"
ListItem li = RadioButtonList1.Items.FindByValue(pizzaOptionFromDB);
if (li != null)
li.Selected = true;
This selects the ListItem with the string "Pizza with tuna".
Revision number 4, Thursday, June 11, 2009 8:23:29 AM by demugger
You must Login to comment.
Sat, Jan 2, 2010 6:43 AM
Nice thanks , it helped me :)