c# - 将 Asp 单选按钮属性(值)设置为字符串

标签 c# html asp.net .net

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

提前致谢。

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
    }

最佳答案

对于网络表单:

<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-在一些按钮点击

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

希望你理解并为你工作。

关于c# - 将 Asp 单选按钮属性(值)设置为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17035914/

相关文章:

c# - 使用 '/' 分隔符从其余数据中拆分 Url

html - 两个 <img> 没有间距

Html css 图片问题 windows IE FF GChrome

asp.net - 服务于应用程序池 'Classic .NET AppPool' 的进程与 Windows Process Activation Service 发生致命通信错误

c# - 为 IIS 中托管的 WCF 服务创建自定义 .svc 处理程序

c# - Linq过滤包括

c# - DirectorySearcher 异步使用 await

c# - 自动调整面板上呈现的多个表单的大小

html - 使每个 <li> 的动画效果都比前一个晚

asp.net - 通过 CSS 设置单选按钮启用/禁用