Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net radiobuttonlist will not selectindex

I have a radio button list...

            <asp:RadioButtonList ID="rblCollectOptions" runat="server" CssClass="radiolist">
            <asp:ListItem Value="Collect" Text="Collect from this address"></asp:ListItem>
            <asp:ListItem Value="DropOff" Text="Drop off at Depot (UK only)"></asp:ListItem>
        </asp:RadioButtonList>

I also have a link button on the page to "enter address manually" which I want to set the radio button to "Collect" value.

I tried...

rblCollectOptions.SelectedIndex = 0;

and

rblCollectOptions.Items[0].Selected = true;

both work if no option is already selected, but if I manually set the radio button to another option, or set a default selection, the link button does not work.

like image 250
Stuart Avatar asked Nov 04 '22 02:11

Stuart


1 Answers

Call ClearSelection or set SelectedIndex = -1 before you set the selected item.

rblCollectOptions.ClearSelection();

or

rblCollectOptions.SelectedIndex = -1;
like image 168
Adil Avatar answered Nov 11 '22 14:11

Adil