Search code examples
asp.netradiobuttonlist

ASP.Net Radio Button List Problem


im having some trouble with the radio button list in ASP.net, for some reason it wont let me select the 2nd item in the radio button list ( index of 1) when i select this item the selected item goes back to 0 (the first item). when i debug the code to see what the selected item is, it shows 0 for some reason, even though i press the 2nd item ( the index should be 1)

can any one think of what i might be doing wrong here ??

on the web form side i have this

                        <asp:RadioButtonList ID="RadioButtonList1" runat="server" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged" AutoPostBack="true">
                        </asp:RadioButtonList>

then on the script side, the radio button list is populated by going through an array like so

    for (i = 0; i < answersJArray[i].Length; i++)
    {
        RadioButtonList1.Items.Add(answersJArray[i].ToString());
    }

Solution

  • It would be good if you could show us a little of your codebehind or describe your process and events a little more thoroughly. I'd say offhand that you must be databinding the selection of the radiobuttonlist or initializing its selection by some criteria on page load.

    If either of these are correct, you'll want to insert a !IsPostBack conditional to make sure you aren't overriding any potential events by rebinding the control inappropriately or reassigning its selected option programmatically.