前台有代码: <td>
<asp:RadioButtonList ID="Select_3" runat="server">
<asp:ListItem Selected="true" Value="0">不符合</asp:ListItem>
<asp:ListItem Value="1">符合</asp:ListItem>
</asp:RadioButtonList>
</td>因为有ID = Select_1至Select-52,我就使用下面的代码: string strRet = "".ToString();
string subSelect = "Select_";
for (int i = 1; i <= 52; i++)
{
subSelect = subSelect + i.ToString();
Control ctl = this.FindControl(subSelect);
RadioButtonList rbl = (RadioButtonList)ctl;
if (rbl != null)
{
strRet = strRet + rbl.SelectedValue + "-";
}
} strRet = strRet.Substring(0, strRet.Length - 1);
return strRet;
但是findControl查找到的一直是null。我应该怎么做?
<asp:RadioButtonList ID="Select_3" runat="server">
<asp:ListItem Selected="true" Value="0">不符合</asp:ListItem>
<asp:ListItem Value="1">符合</asp:ListItem>
</asp:RadioButtonList>
</td>因为有ID = Select_1至Select-52,我就使用下面的代码: string strRet = "".ToString();
string subSelect = "Select_";
for (int i = 1; i <= 52; i++)
{
subSelect = subSelect + i.ToString();
Control ctl = this.FindControl(subSelect);
RadioButtonList rbl = (RadioButtonList)ctl;
if (rbl != null)
{
strRet = strRet + rbl.SelectedValue + "-";
}
} strRet = strRet.Substring(0, strRet.Length - 1);
return strRet;
但是findControl查找到的一直是null。我应该怎么做?
应该是 容器控件.findcontrol
还有 findcontrol,我忘记是不是会帮你模糊查询 Select_了。这个记不清了。
应该改为Control ctl = Select_3.FindControl(subSelect);
这样可以找到与 Select_3 在同一个控件树名称空间内的其它 1~52 控件。