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

This is a discussion on RadioButtonList does not allow you to select a ListItem other than the first one that has a specified value - DOTNET ; 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 ...

+ Reply to Thread
Results 1 to 2 of 2

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

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

    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@hotmail.com
    http://www.nathansokalski.com/



  2. Default Re: RadioButtonList does not allow you to select a ListItem other than the first one that has a specified value

    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.
    --
    Nathan Sokalski
    njsokalski@hotmail.com
    http://www.nathansokalski.com/

    "Nathan Sokalski" <njsokalski@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
    > njsokalski@hotmail.com
    > http://www.nathansokalski.com/
    >




+ Reply to Thread

Similar Threads

  1. Placing a TextBox next to a ListItem in a RadioButtonList
    By Application Development in forum DOTNET
    Replies: 0
    Last Post: 11-08-2007, 06:04 PM
  2. problem with ListItem databinding
    By Application Development in forum DOTNET
    Replies: 1
    Last Post: 11-07-2007, 08:15 PM
  3. Replies: 0
    Last Post: 10-25-2007, 09:31 AM
  4. How to bring a ListItem to the top
    By Application Development in forum basic.visual
    Replies: 0
    Last Post: 03-29-2007, 10:17 AM
  5. ListItem Edit
    By Application Development in forum basic.visual
    Replies: 2
    Last Post: 01-30-2004, 09:19 AM