Asp.net 动态radiobuttonlist selectedindex不';行不通

Asp.net 动态radiobuttonlist selectedindex不';行不通,asp.net,vb.net,Asp.net,Vb.net,我的网站上有5个RadioButton列表 <div class="col-md-6"> <asp:RadioButtonList ID="CR1" CssClass="radioButtonList" runat="server" EnableViewState="true" AutoPostBack="true" RepeatDirection="Horizontal" > <asp:ListItem Text='1' Value="1"></

我的网站上有5个RadioButton列表

<div class="col-md-6">

 <asp:RadioButtonList ID="CR1" CssClass="radioButtonList" runat="server" EnableViewState="true" AutoPostBack="true" RepeatDirection="Horizontal" >
 <asp:ListItem Text='1' Value="1"></asp:ListItem>
 <asp:ListItem Text='2' Value="2"></asp:ListItem>
 <asp:ListItem Text='3' Value="3"></asp:ListItem>                           
 </asp:RadioButtonList>
但是这不起作用,当我使用CR1.SelectedIndex=-1时,它可以正常工作


有什么建议可以解释为什么我不能在一个循环中工作吗?

您找不到的
RadioButtonList
,因为它可能不是顶级容器控件的直接子项。Me.Page.FindControl不会在顶层容器的层次结构中递归搜索。您需要radiobuttonlist的直接父级

该方法仅搜索页面的即时或顶级, 容器;它不会在命名中递归搜索控件 页面上包含的容器。访问从属命名中的控件的步骤 容器,调用该容器的FindControl方法

您可以使父div服务器可访问并通过它查找

<div id="divRBL" runat="server" class="col-md-6">

如果您有多个包含RadioButtonList的div,那么您可以按顺序分配ID,以便在运行时生成它们的ID,就像您在
FindControl
中对
RadioButtonLists
所做的那样。您是否调试以查看是否通过FindControl获得RadioButtonList?我在rbl上获得了“System.NullReferenceException”。在调试i中,SelectedIndex=-1还看到findcontrol值为Nothing,我不明白为什么….???RadioButtonList在GridView或Repeater等中?请显示其所有父项的层次结构的相关HTML。我尝试了所有父项…radiobuttonlist位于容器-form-Panel-Panel body-div中。每个父项的错误为:{InnerText={System.Web.HttpException(0x80004005):无法获取bdPanel的内部内容,因为内容不是文字。在System.Web.UI.HtmlControl.HtmlContainerControl.get_InnerHtml()在System.Web.UI.HtmlControl.HtmlContainerControl.get_InnerText()}请添加相关的HTML
<div id="divRBL" runat="server" class="col-md-6">
Dim rbl As RadioButtonList = divRBL.FindControl("CR" & i )