Solved

Select a radio button from the radiobutton group list

Posted on 2011-09-15
4
422 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now