Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > RadioButtonList does not allow you to select a ListItem other than the first one that has a specified value

Reply
Thread Tools

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

 
 
Nathan Sokalski
Guest
Posts: n/a
 
      11-27-2007
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
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.nathansokalski.com/


 
Reply With Quote
 
 
 
 
Nathan Sokalski
Guest
Posts: n/a
 
      11-28-2007
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
(E-Mail Removed)
http://www.nathansokalski.com/

"Nathan Sokalski" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
> (E-Mail Removed)
> http://www.nathansokalski.com/
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
RadioButtonList does not allow you to select a ListItem other than the first one that has a specified value Nathan Sokalski ASP .Net 1 11-28-2007 02:07 AM
RadioButtonList.SelectedIndexChanged not raised when the ListItem has Selected="True" Nathan Sokalski ASP .Net 0 10-25-2007 02:31 PM
<asp:ListItem Value="0">blank choice</asp:ListItem> ? Jim in Arizona ASP .Net 7 11-22-2006 08:31 AM
ropdownlist listitem.value not working - returns listitem.text instead Mad Scientist Jr ASP .Net 2 06-29-2004 01:13 PM



Advertisments