Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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
    }
share|improve this question
    
are you working on web forms or win forms. –  Rahul Jun 11 '13 at 5:06
    
working for web forms –  my1 Jun 11 '13 at 6:27
    
then you have to use RadioButtonList, because in RadioButton there is a property for Text but not for Value. –  Rahul Jun 11 '13 at 6:41
    
@Rahul yes you are right, but iam using attribute for radio buton, so how to get that attribute value –  my1 Jun 11 '13 at 6:46

3 Answers 3

up vote 1 down vote accepted
string strResult = rdotest.Attributes["Value"];
share|improve this answer

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.

share|improve this answer

try rdo.SelectedValue instead of rdo.Text

share|improve this answer
    
I can't see selected property for radio button in intellisense –  my1 Jun 11 '13 at 3:40
    
radiobutton has no SelectedValue property but RadioButtonList have. –  Rahul Jun 11 '13 at 3:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.