Repeater获取其中的控件

Gavin_Y 2010-09-19 04:43:20
我现在用Repeater绑定数据,我在HeaderTemplate和FooterTemplate里放了lable和LinkButton控件,为什么我在程序里无法获取这些控件,无法给lable的text属性赋值。
请问各位高手我要怎么做,才能获得那些控件?
...全文
302 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyq11 2010-09-20
  • 打赏
  • 举报
回复
foreach(RepeaterItem item in this.Repeater1.Items)
{ if(item.ItemType == ListItemType.Footer)
{Label l = (Label)item.FindControl("lbl");}
}
Gavin_Y 2010-09-20
  • 打赏
  • 举报
回复
问题解决了。
Label la = rptPrescriptionInfo.Controls[0].FindControl("lblIndexPage") as Label;
Label lblIndexpage = rptPrescriptionInfo.Controls[rptPrescriptionInfo.Controls.Count - 1].FindControl("lblIndexPage") as Label;

这样写就能得到了。
zhwqy84 2010-09-20
  • 打赏
  • 举报
回复
jianshao810 2010-09-20
  • 打赏
  • 举报
回复
foreach(RepeaterItem item in this.Repeater1.Items)
{ if(item.ItemType == ListItemType.Footer)
{Label l = (Label)item.FindControl("lbl");}
}
jianshao810 2010-09-20
  • 打赏
  • 举报
回复
要找到行与列
happy664618843 2010-09-20
  • 打赏
  • 举报
回复
解决了 帮顶
村长_乐 2010-09-20
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 rewoshengqi 的回复:]
引用 10 楼 wuyq11 的回复:
foreach(RepeaterItem item in this.Repeater1.Items)
{ if(item.ItemType == ListItemType.Footer)
{Label l = (Label)item.FindControl("lbl");}
}

貌似应该跟gridview差不多吧 楼主 慢慢试试呗
[/Quote]
差不多吧...
dengNeeo 2010-09-20
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 wuyq11 的回复:]
foreach(RepeaterItem item in this.Repeater1.Items)
{ if(item.ItemType == ListItemType.Footer)
{Label l = (Label)item.FindControl("lbl");}
}
[/Quote]
貌似应该跟gridview差不多吧 楼主 慢慢试试呗
parverxiao 2010-09-20
  • 打赏
  • 举报
回复
if (Repeater1.Items.Count>0)
{
foreach (RepeaterItem item in Repeater1.Items)
{
TextBox txtname = (TextBox)item.FindControl("txtName");
Label lbl = (Label)item.FindControl("lbimg");
}
}
............然后再赋值操作
dalmeeme 2010-09-19
  • 打赏
  • 举报
回复
当设置了HeaderTemplate和FooterTemplate后:
HeaderTemplate是Items[0]和FooterTemplate是Items[n-1]

Repeater1.Items[0].FindControl(...)
ysz89757 2010-09-19
  • 打赏
  • 举报
回复
lable的text有没有runat="server"
要一层层找。this.XXX.XXX.RepeaterId.findcontrol("labelID")
zhangdoublepan 2010-09-19
  • 打赏
  • 举报
回复
通过RepeaterItem 来找
zm81499259 2010-09-19
  • 打赏
  • 举报
回复
用循环找
yangjinan0729 2010-09-19
  • 打赏
  • 举报
回复
Gavin_Y 2010-09-19
  • 打赏
  • 举报
回复
我用的 Label la = rptPrescriptionInfo.FindControl("lblIndexpage") as Label 找不出来
lybjust 2010-09-19
  • 打赏
  • 举报
回复
一样的一层一层找下去
酷儿 2010-09-19
  • 打赏
  • 举报
回复
首先找repeater 找到之后再去找控件

62,249

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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