C# 将Asp单选按钮属性(值)设置为字符串的步骤

C# 将Asp单选按钮属性(值)设置为字符串的步骤,c#,html,asp.net,.net,C#,Html,Asp.net,.net,在下面提到的代码中,iam将属性“value”添加到单选按钮。我需要知道如何将单选按钮“value”属性设置为字符串 提前谢谢 protected void Page_Load(object sender, EventArgs e) { RadioButton rdoAuthModeSingleFactor = new RadioButton(); rdoAuthModeSingleFactor.Text = authModeObj["AuthenticationModes"].

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

提前谢谢

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
    }

请尝试rdo.SelectedValue而不是rdo.Text

用于Web表单:

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

希望您理解并为您工作。

我看不到intellisense中单选按钮的选定属性
radiobutton
没有
SelectedValue
属性,但
RadioButtonList
有。您是否正在处理
web表单
win表单
。处理web表单,而您必须使用
RadioButtonList
,因为在
RadioButton
中有一个属性用于
Text
而不是
Value
@Rahul是的,你是对的,但是我使用radio buton的属性,那么如何获取该属性值呢
string strResult = rdotest.Attributes["Value"];
string strResult = rdotest.Attributes["Value"];