65.9K
CodeProject 正在变化。 阅读更多。
Home

RadioButtonList

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0投票)

2013 年 10 月 11 日

CPOL
viewsIcon

11741

RadioButtonList 可用于在一组选项中选择一个选项。 默认情况下选择了“鸡蛋披萨”项。    <asp:RadioButtonList

RadioButtonList 可用于在一组选项中选择一个选项。 默认情况下选择了“鸡蛋披萨”项。

    <asp:RadioButtonList ID="RadioButtonList1" runat="server">
                <asp:ListItem Selected="True">鸡蛋披萨</asp:ListItem>
<asp:ListItem>金枪鱼披萨</asp:ListItem>
<asp:ListItem>火腿披萨</asp:ListItem>

   </asp:RadioButtonList>

 

从数据库设置选定的项

如果从数据库加载数据,有时您希望根据数据库中的值选择某个项。

您可以这样做:

    string pizzaOptionFromDB = someCode.getPizzaFromDB();  // 数据库返回  "金枪鱼披萨" 
    ListItem li = RadioButtonList1.Items.FindByValue(pizzaOptionFromDB);
    if (li != null)
        {
            li.Selected = true;
        }

这将选择字符串为“金枪鱼披萨”的 ListItem。

 

© . All rights reserved.