Findcontrol获取的控件为空

wanglinlin0204 2016-09-19 09:05:01
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
...全文
180 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wanglinlin0204 2016-09-20
  • 打赏
  • 举报
回复
解决了,是用了母版页, RadioButtonList rbl = (Page.Master.FindControl("ContentPlaceHolder1").FindControl(rblname) as RadioButtonList); 加上红色部分就好了
  • 打赏
  • 举报
回复
你贴出的代码根本无法判断该如何编程。因为你没有给出符合 NamingContainer 范围的 aspx 代码设计。
  • 打赏
  • 举报
回复
FindControl 函数查询当前 INamingContainer 范围内部的控件,不是去耗费时间去遍历下一层控件。 你先说明一下,你从哪里学习 asp.net 的呢?贴出来你学习的 FindControl 的教程。
wanglinlin0204 2016-09-19
  • 打赏
  • 举报
回复
各位大神指点指点啊,findcontrol到底怎么用啊?

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧