简体   繁体   中英

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.

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

rblCollectOptions.ClearSelection();

or

rblCollectOptions.SelectedIndex = -1;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM