473,396 Members | 1,935 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Get the index of the selected button in radiobuttonlist

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.

Nov 19 '05 #1
5 1809
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/

Nov 19 '05 #2
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"?

Nov 19 '05 #3

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
}

"sv****************@gmail.com" wrote:
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.

Nov 19 '05 #4
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/

Nov 19 '05 #5
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 :)

Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: juststarter | last post by:
Hello, I have an aspx file where i've put a placeholder element. On load i create dynamically a table which contains a checkbox and a radiobuttonlist in each tablerow . The radiobuttonlist...
2
by: mg | last post by:
After a selection is made in the following RadioButtonList <asp:RadioButtonList id="RadioButtonList1" runat="server"> <asp:ListItem Value="Y"></asp:ListItem> <asp:ListItem...
1
by: Empire City | last post by:
I have an ASP.NET form with a DataGrid and Button. I want to put a RadioButtonList in a DataGrid cell. I bind it to an ArrayList which has a ListItem in the cell. The display part works fine. I...
3
by: Dot net work | last post by:
Is it possible to have a radiobuttonlist control appear on a webform without any radio buttons checked to begin with? I would really like to make sure that the user specifically chooses a radio...
4
by: juststarter | last post by:
Hello, I have an aspx file where i've put a placeholder element. On load (page_load) i create dynamically an html table which contains a checkbox and a radiobuttonlist in each tablerow . The...
0
by: John Meyer | last post by:
index: <%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %> <!DOCTYPE html PUBLIC...
2
by: Vahagn | last post by:
Hi, how do I retrieve the chosen value from a RadioButtonList? I have a RadioButtonList that is populated dynamically with a "Next" button. Ie, I have a list of questions each with 2-3 answer...
0
by: CURTISLESPERANCE | last post by:
Hi, I have a radiobuttonlist within a nested repeater, resulting in multiple radiobuttonlists. On a button click how do I find out what those selected values of the radiobuttons were? Code...
6
by: SAL | last post by:
hello, I'm using a radiobuttonlist in an updatepanel in an item template in a Gridview control. I'm populating the radiobuttonlist in the RowDataBound event. I have the control toolkit registered...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.