Findcontrol获取的控件为空

.Net技术 码拜 8年前 (2016-09-22) 1065次浏览
int an1=0;
int bn1=0;
int d1= 0;
string s1=””;
for (int i = 1; i <= 41; i=i+4)
{
string rblname = “RadioButtonList” + i.ToString();
 RadioButtonList rbl =(this.FindControl(rblname) as RadioButtonList);
if (rbl.SelectedValue == “a”) an1=an1+1;
else bn1++;
}
<asp:RadioButtonList ID=”RadioButtonList1″ runat=”server” RepeatDirection=”Horizontal”>
<asp:ListItem Value=”a”> (a) 试试看</asp:ListItem>
<asp:ListItem Value=”b”>(b) 深思熟虑</asp:ListItem>
</asp:RadioButtonList>
rbl总是为null
解决方案

20

你贴出的代码根本无法判断该怎么样编程。原因是你没有给出符合 NamingContainer 范围的 aspx 代码设计。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Findcontrol获取的控件为空
喜欢 (0)
[1034331897@qq.com]
分享 (0)