【问题标题】:How to set value to RadioButtonList Item in ASP.NET如何在 ASP.NET 中为 RadioButtonList 项设置值
【发布时间】:2015-08-01 21:50:07
【问题描述】:

我有一个 RadioButtonList,其中包含 2 个值 - “是”和“否”。我希望每次用户进入表单页面时,该值都将设置为他第一次填写表单时选择的值。使用TextBoxes 没有问题,只有RadioButtonList。 以下是代码:

        <asp:RadioButtonList ID="RadioButtonList1" runat="server">
        <asp:ListItem Value="Yes"></asp:ListItem>
        <asp:ListItem Value="No"></asp:ListItem>
        </asp:RadioButtonList>

背后的代码: (如果用户在第一次填写表单时选择了“否”单选按钮,则 'if' 会在数据库中检查,??? 是我需要的:))

            if ((String)cmd3.ExecuteScalar() == "No")
        {
            ???
        }

我试过RadioButtonList1.Items.FindByValue("No").Selected = true;,但没用。

如果我不清楚,请告诉我,谢谢。伊丹。

【问题讨论】:

    标签: asp.net radiobuttonlist


    【解决方案1】:

    怎么样:

     if ((String)cmd3.ExecuteScalar() == "No")
     {
        RadioButtonList1.SelectedIndex  = 1;
     }
     else
     {
        RadioButtonList1.SelectedIndex  = 0;
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-07
      • 2015-08-16
      • 2011-04-16
      • 2019-12-13
      • 2011-03-31
      • 1970-01-01
      • 2010-12-21
      • 2010-10-02
      相关资源
      最近更新 更多