Asp.net radiobuttonlist will not select index

I have a list of radio buttons ...

<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 the address manually", which I want to set for the "Collect" value.

I tried...

 rblCollectOptions.SelectedIndex = 0; 

and

 rblCollectOptions.Items[0].Selected = true; 

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

+4
source share
1 answer

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

 rblCollectOptions.ClearSelection(); 

or

 rblCollectOptions.SelectedIndex = -1; 
+1
source

Source: https://habr.com/ru/post/1468935/


All Articles