Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2005

Tip: Looking for answers? Try searching our database.

Get the index of the selected button in radiobuttonlist

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
svein.erik.storkas@gmail.com - 31 Oct 2005 18:29 GMT
How can i get the index of the button that is selected in a
radiobuttonlist?
I have a radiobuttonlist that contains 5 buttons, and i do a switch on
what index that is selected, like this:

Session["rblMarked"] = GetIndexString( rblMarked.SelectedIndex );

Session["rblCustomersSeriosly"] = GetIndexString(
rblCustomersSeriosly.SelectedIndex );

...

then the method GetIndexString:

private string GetIndexString( int index )
        {
            string temp = "";

            switch(index) {
                case 0:
                    temp = "Stor innverknad";
                    break;
                case 1:
                    temp = "Ein del innverknad";
                    break;
                case 2:
                    temp = "Middels innverknad";
                    break;
                case 3:
                    temp = "Lite innverknad";
                    break;
                case 4:
                    temp = "Ingen innverknad";
                    break;
            }

            return temp;
        }

But the number 0 is coming from .SelectedIndex no matter what button i
push...why?

I really appreciate some quick help..i've got time pressure on this
project! :)

Thanks!
Svein Erik.
Jason Kester - 31 Oct 2005 19:35 GMT
You might want to step through your code and make sure you're not
re-filling that list before you get around to reading from it.  That's
the most common reason for this happening.  If you put a breakpoint at
the first line of that GetIndexString method and another at the first
line of FillThatList() (or whatever is binding that list), you might
see that FillThatList gets called first.  If that happens, it will
throw away your selection and you'll get the results you're seeing.

The solution is usually to stick FillThatList() into an if(!isPostBack)
block.

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

---
Get your own Travel Blog, with itinerary maps and photos!
http://www.blogabond.com/
svein.erik.storkas@gmail.com - 31 Oct 2005 20:09 GMT
Thanks, but i have set breakpoints, and there is nothing that gets
called in between...The only thing worth mentioning is that both Value
and Text fields of the radiobuttonlist properties are blank...does this
have anything to do with the "problem"?
Jason Kester - 31 Oct 2005 21:04 GMT
And the Items collection on the list?  Does that come back empty too?

If not, you can spin through the list and look for the first one marked
.Selected.  A bit more effort, but it will get you there.

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

---
Get your own Travel Blog, with itinerary maps and photos!
http://www.blogabond.com/
svein.erik.storkas@gmail.com - 31 Oct 2005 23:06 GMT
I finally found a "hack", i had to set value to   . Then it worked
like it should..it seemes that sometimes you have to make a workaround
out of the standards..?

Well, thank you very much for your help :)
Sreejith Ram - 31 Oct 2005 20:57 GMT
Are you databinding every time in page_load by any chance?

the databinding should happen like below

 if(!Page.PostBack())
     {
        //databind the radio button list here
    }

> How can i get the index of the button that is selected in a
> radiobuttonlist?
[quoted text clipped - 43 lines]
> Thanks!
> Svein Erik.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.