【问题标题】:To set Asp Radio button attribute (value) to a string将 Asp 单选按钮属性(值)设置为字符串
【发布时间】:2013-06-06 19:39:29
【问题描述】:

在下面提到的代码中,我将属性“值”添加到单选按钮。我需要知道如何将单选按钮的“值”属性设置为字符串。

提前致谢。

protected void Page_Load(object sender, EventArgs e)
{
    RadioButton rdoAuthModeSingleFactor = new RadioButton();
    rdoAuthModeSingleFactor.Text = authModeObj["AuthenticationModes"].ToString();
    string authModeIdVal = authModeObj["AuthenticationModeId"].ToString();
    rdoAuthModeSingleFactor.GroupName = "AuthModes";
    rdoAuthModeSingleFactor.ID = "AuthModeRdoID";
    rdoAuthModeSingleFactor.Attributes.Add("Value", authModeIdVal);
    plhldrAuthModes1.Controls.Add(rdoAuthModeSingleFactor);
}

protected void btnAuthModeSave_Click(object sender, EventArgs e)
        {
    //Here iam using placeholder functionalities
    // radio button object name is rdo
            string authenticationModeCheckedVal = rdo.Text;  // how to get value of radio button instead of text
    }

【问题讨论】:

  • 你正在处理web formswin forms
  • 处理网络表单
  • 那么你必须使用RadioButtonList,因为在RadioButton 中有一个Text 的属性,但Value 没有。
  • @Rahul 是的,你是对的,但是我正在使用单选按钮的属性,那么如何获取该属性值

标签: c# html asp.net .net


【解决方案1】:

尝试 rdo.SelectedValue 而不是 rdo.Text

【讨论】:

  • 我在智能感知中看不到单选按钮的选定属性
  • radiobutton 没有 SelectedValue 属性,但 RadioButtonList 有。
【解决方案2】:

对于网络表单:

<asp:RadioButtonList ID="rdogender" runat="server" RepeatLayout="Flow">
    <asp:ListItem Value="Male">Male</asp:ListItem>
    <asp:ListItem Value="Female">Female</asp:ListItem>
</asp:RadioButtonList>

还有 CS-in 一些按钮点击

string value=rdogender.SelectedItem.Value.ToString();

希望您理解并为您工作。

【讨论】:

    【解决方案3】:
    string strResult = rdotest.Attributes["Value"];
    

    【讨论】:

      猜你喜欢
      • 2019-11-01
      • 1970-01-01
      • 2022-01-06
      • 2013-06-28
      • 1970-01-01
      • 1970-01-01
      • 2014-08-23
      • 2013-08-25
      • 1970-01-01
      相关资源
      最近更新 更多