Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

RadioButtonList

0.00/5 (No votes)
11 Jun 2009 1  
A RadioButtonList can be used to select 1 option within several options. The item Pizza with egg is selected by default.    <asp:RadioButtonList

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

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>

   </asp:RadioButtonList>

 

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".

 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here