Solved

Select a radio button from the radiobutton group list

Posted on 2011-09-15
4
441 Views
Last Modified: 2012-05-12
How can I select a radiobutton from the grouplist at C# server side? Thanks.

                       <asp:RadioButtonList ID="radiobtnlist" runat="server" AutoPostBack="true"
                               onselectedindexchanged="RadioList_SelectedIndexChanged"
                               RepeatDirection="Horizontal" Width="300px">
                               <asp:ListItem Value="type1">type1</asp:ListItem>
                               <asp:ListItem Value="type2">type2</asp:ListItem>
                               <asp:ListItem Value="type3">type3</asp:ListItem>
                               <asp:ListItem Value="type4">type4</asp:ListItem>
                         </asp:RadioButtonList>

0
Comment
Question by:minglelinch
  • 2
  • 2
4 Comments
 
LVL 7

Expert Comment

by:Norush
ID: 36543577
Try with:


                  foreach (ListItem item in radiobtnlist.Items)
                  {
                        //Doo stuff with the item
                        //for example:
                        item.Attributes.Add("onClick", "resumeHeaderFormattingStyle = 'resumeStyleHeading10'; resumeContentFormattingStyle = 'resumeStyleContent10';");
                  }
0
 
LVL 1

Author Comment

by:minglelinch
ID: 36543762
What I'm doing is - Based on the value I got fom DB, I need to select the coresponding radio button,maybe the first, the second one  or the third, the four one.

foreach { ..} looks like adding onClick for each button. Is there an index field for the radio button group?

0
 
LVL 7

Accepted Solution

by:
Norush earned 500 total points
ID: 36543850
Something like this ?

int i;
i = 1;  //Get your value from the DB here
radiobtnlist.Items[i].Selected = true;

Open in new window

0
 
LVL 1

Author Closing Comment

by:minglelinch
ID: 36544372
Thanks. This is what I need. It works now.
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question