【问题标题】:Set radio button selected value according to the value retrieved from database result?根据从数据库结果中检索到的值设置单选按钮选择的值?
【发布时间】:2015-11-11 10:34:09
【问题描述】:
 <asp:RadioButtonList ID="rbnPropertyType" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow">
    <asp:ListItem Text="Commercial"   Value="1" />
     <asp:ListItem Text="Residential" Value="2" />

这是 ma aspx 代码。 .cs 代码是

? = dtPolicyInfo.Rows[0]["PropertyType"].ToString();

如何根据数据库结果设置单选按钮选择值?

【问题讨论】:

标签: c# asp.net radio-button


【解决方案1】:

试试这个可能会有所帮助:

rbnPropertyType.ClearSelection();
 rbnPropertyType.SelectedIndex = rbnPropertyType.Items.IndexOf(rbnPropertyType.Items.FindByValue(dtPolicyInfo.Rows[0]["PropertyType"].ToString()));

【讨论】:

    【解决方案2】:
    string PropertyTypeID= dtPolicyInfo.Rows[0]["PropertyType"].ToString();
    rbnPropertyType.Items.FindByText(PropertyTypeID).Selected = true;
    

    【讨论】:

      【解决方案3】:

      首先,清除选中的列表:

      rbnPropertyType.SelectedIndex = -1;
      

      现在按值或文本搜索项目,然后选择它。

      rbnPropertyType.Items.FindByValue(dtPolicyInfo.Rows[0]["PropertyType"].ToString()).Selected = true;
      rbnPropertyType.Items.FindByText(dtPolicyInfo.Rows[0]["PropertyType"].ToString()).Selected = true;
      

      【讨论】:

        猜你喜欢
        • 2013-03-19
        • 1970-01-01
        • 1970-01-01
        • 2014-01-18
        • 1970-01-01
        • 2019-09-16
        • 2016-06-28
        • 2017-05-26
        • 2018-06-03
        相关资源
        最近更新 更多