2014-01-15 45 views
0

我得到這個錯誤,而試圖使用VB代碼禁用單選按鈕列表上的第一個單選按鈕的大小:指數超出範圍。必須爲非負且小於集合參數

RadioButtonList1.Items(0).Enabled = False 

下面是ASPX代碼

<td class="TDLR"> 
    <asp:RadioButtonList ID="RadioButtonList1" runat="server" DataSourceID="SqlFollow"   DataTextField="FollowDesc" DataValueField="FollowID"> 
    </asp:RadioButtonList> 
     <asp:SqlDataSource ID="SqlFollow" runat="server" 
     ConnectionString="<%$ ConnectionStrings:SampleConnectionString %>" 
     SelectCommand="Select FollowID, FollowDesc FROM FollowUp WHERE FollowID > 30"> 
    </asp:SqlDataSource> 
    </td> 
+3

該錯誤表明您正試圖在RadioButtonList被填充之前設置Enabled值。驗證你的select語句返回一個值。另外,你在哪裏設置啓用值? – AWinkle

+0

此外,你有'ViewState'打開?這也會稍微修改流量。 –

+0

謝謝。對不起,編程有點新意。我打算禁用網格上的第一個單選按鈕。任何幫助請。 – user3199339

回答

1

檢查Items.Count第一:

編輯:嘗試代碼Page_PreRender象下面這樣:

Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender 
    If RadioButtonList1.Items.Count > 0 Then 
     RadioButtonList1.Items(0).Enabled = False 
    End If 
End Sub 
+0

謝謝。我嘗試了items.count,但它返回不計數。我相信它沒有把它看成一個清單。我基本上想要禁用正在填充在網格上的第一個單選按鈕。任何幫助請 – user3199339

+0

@ user3199339 - 我相信你正試圖在創建它之前將其禁用。嘗試在Page_PreRender中做到這一點。請參閱我的編輯。 – afzalulh

相關問題