HighTechTalks DotNet Forums  

RadioButtonList does not allow you to select a ListItem other than the first one that has a specified value

ASP.net Web Controls microsoft.public.dotnet.framework.aspnet.webcontrols


Discuss RadioButtonList does not allow you to select a ListItem other than the first one that has a specified value in the ASP.net Web Controls forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Nathan Sokalski
 
Posts: n/a

Default RadioButtonList does not allow you to select a ListItem other than the first one that has a specified value - 11-27-2007 , 04:00 PM






I have a RadioButtonList with more than one ListItem that has a certain
Value. If I select a ListItem with that Value, the one that is selected is
the first ListItem with that Value. For example, if I had the following
ListItems:

<asp:ListItem Text="Boardgames" Value="12.00"/>
<asp:ListItem Text="Stuffed Animals" Value="8.00"/>
<asp:ListItem Text="Pens" Value="3.00"/>
<asp:ListItem Text="Mouse Pad" Value="2.00"/>
<asp:ListItem Text="Screwdriver" Value="12.00"/>
<asp:ListItem Text="Notecards" Value="3.00"/>

If someone were to select Notecards, the ListItem that would end up being
selected would be Pens, and if Screwdriver was selected, it would actually
select Boardgames. This problem only occurs when ListItems have the same
value. I am using AJAX when this is occurring. Does anybody have any
suggestions for an easy way to avoid this problem without changing the
Values? Thanks.
--
Nathan Sokalski
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/



Reply With Quote
  #2  
Old   
Nathan Sokalski
 
Posts: n/a

Default Re: RadioButtonList does not allow you to select a ListItem other than the first one that has a specified value - 11-27-2007 , 08:07 PM






I have finally found a simple solution, here is the code:

If Not String.IsNullOrEmpty(Me.Request.Form("__EVENTTARGE T")) Then 'Make
sure there is a value; there is no value when the page is first launched
Dim eventtarget As String = Me.Request.Form("__EVENTTARGET").Replace("$",
"_") 'Replace the $'s in the returned value with underscores; underscores
are what is returned by the ClientID property
If eventtarget.StartsWith(Me.rblChoices.ClientID) Then
Me.rblChoices.SelectedIndex =
CInt(eventtarget.Substring(eventtarget.LastIndexOf ("_") + 1)) 'Parse the
string to retrieve the index
End If

This code should be placed as early as possible in the Page lifecycle. I
placed it in the Page's Load event, since the properties are not generally
used or available before then. I have not extensively tested this for
compatibility for all scenarios. As you can see from my original posting, my
original scenario had static ListItems, so you may want to do some testing
of your own if you are dynamically populating the RadioButtonList.
--
Nathan Sokalski
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/

"Nathan Sokalski" <njsokalski (AT) hotmail (DOT) com> wrote

Quote:
I have a RadioButtonList with more than one ListItem that has a certain
Value. If I select a ListItem with that Value, the one that is selected is
the first ListItem with that Value. For example, if I had the following
ListItems:

asp:ListItem Text="Boardgames" Value="12.00"/
asp:ListItem Text="Stuffed Animals" Value="8.00"/
asp:ListItem Text="Pens" Value="3.00"/
asp:ListItem Text="Mouse Pad" Value="2.00"/
asp:ListItem Text="Screwdriver" Value="12.00"/
asp:ListItem Text="Notecards" Value="3.00"/

If someone were to select Notecards, the ListItem that would end up being
selected would be Pens, and if Screwdriver was selected, it would actually
select Boardgames. This problem only occurs when ListItems have the same
value. I am using AJAX when this is occurring. Does anybody have any
suggestions for an easy way to avoid this problem without changing the
Values? Thanks.
--
Nathan Sokalski
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.