在下面提到的代码中,我将属性“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
}
答案 0 :(得分:3)
对于网络表单:
<asp:RadioButtonList ID="rdogender" runat="server" RepeatLayout="Flow">
<asp:ListItem Value="Male">Male</asp:ListItem>
<asp:ListItem Value="Female">Female</asp:ListItem>
</asp:RadioButtonList>
并点击某些按钮
string value=rdogender.SelectedItem.Value.ToString();
希望你理解并为你工作。
答案 1 :(得分:3)
string strResult = rdotest.Attributes["Value"];
答案 2 :(得分:0)
尝试 rdo.SelectedValue 而不是 rdo.Text