|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
RadioButtonList does not allow you to select a ListItem other than the first one that has a specifieValue. 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. I have finally found a simple solution, here is the code:
If Not String.IsNullOrEmpty(Me.Request.Form("__EVENTTARGET")) 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. Show quote "Nathan Sokalski" <njsokal***@hotmail.com> wrote in message news:elGMuDUMIHA.3940@TK2MSFTNGP05.phx.gbl... >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 > njsokal***@hotmail.com > http://www.nathansokalski.com/ > |
|||||||||||||||||||||||