指数超出范围。必须是非负数且小于集合参数的大小

时间:2014-01-15 17:55:07

标签: asp.net vb.net indexing

尝试使用vb代码禁用radiobutton列表中的第一个单选按钮时出现此错误:

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>

1 个答案:

答案 0 :(得分: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