2013-03-13 99 views
4

我有一個單選按鈕列表...asp.net單選按鈕列表不會selectindex

  <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> 

我也有頁面上的鏈接按鈕,「手動輸入地址」,我想設置的單選按鈕「收集」價值。

我想...

rblCollectOptions.SelectedIndex = 0; 

rblCollectOptions.Items[0].Selected = true; 

都工作,如果沒有選項已經被選中,但如果我手動設置的單選按鈕,其他選項,或設置默認的選擇,鏈接按鈕不起作用。

回答

1

撥打ClearSelection或設置SelectedIndex = -1然後再設置所選項目。

rblCollectOptions.ClearSelection(); 

rblCollectOptions.SelectedIndex = -1; 
+0

完美!謝謝,我沒有想到這一點,我認爲它會像'dropdownlist'一樣工作。 – Stuart 2013-03-13 11:11:36