Vignesh
Vignesh

Reputation: 1518

To set Asp Radio button attribute (value) to a string

In the below mentioned code iam adding the attribute 'value' to the radio button. I need to know how to set the radio button 'value' attribute to a string.

Thanks in advance.

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
    }

Upvotes: 4

Views: 15839

Answers (3)

user2256194
user2256194

Reputation: 48

string strResult = rdotest.Attributes["Value"];

Upvotes: 3

Rahul
Rahul

Reputation: 5636

For Web Forms :

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

And CS-in some button click

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

Hope you understand and works for you.

Upvotes: 4

himadri
himadri

Reputation: 638

try rdo.SelectedValue instead of rdo.Text

Upvotes: 0

Related Questions