获取repeater控件模版列中的控件
生活随笔
收集整理的這篇文章主要介紹了
获取repeater控件模版列中的控件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
直接用repeater.Findcontrol是獲取不到子控件的,因為子空間實際是在ItemTemplate中的,翻譯一個評論:
if(Roles.IsUserInRole("admin"))
{
Button delete = (Button)rptNotering.Items[0].FindControl("btnDelete");
delete.Visible = true;
Button edit = (Button)rptNotering.Items[0].FindControl("btnEdit");
edit.Visible = true;
}
Inside a repeater are 0-many Items. .Items[x] is where x is the index of the specific itemtemplate instance.
If your repeater returns 10 rows of data, then your repeater returns an instance of ItemTemplate 10 times
and places each instance in the Items[] collection.
Your findcontrol method is not looking inside the ItemTemplate.
Hope this helps :-)
大體意思是:在repeater中有0項,Items[x] 才是制定模版列的實例,如果你的repeater有10行數據,那么你的repeater返回10次ItemTemplate 的實例,每個實例都是在item的集合眾的。
所以我在事件中作了,效果還是可以,只不過這樣的循環感覺不是很好,還有注意你要在repeater數據邦定后再來做如上操作,否則沒效果的。。。。
if(Roles.IsUserInRole("admin"))
{
Button delete = (Button)rptNotering.Items[0].FindControl("btnDelete");
delete.Visible = true;
Button edit = (Button)rptNotering.Items[0].FindControl("btnEdit");
edit.Visible = true;
}
Inside a repeater are 0-many Items. .Items[x] is where x is the index of the specific itemtemplate instance.
If your repeater returns 10 rows of data, then your repeater returns an instance of ItemTemplate 10 times
and places each instance in the Items[] collection.
Your findcontrol method is not looking inside the ItemTemplate.
Hope this helps :-)
大體意思是:在repeater中有0項,Items[x] 才是制定模版列的實例,如果你的repeater有10行數據,那么你的repeater返回10次ItemTemplate 的實例,每個實例都是在item的集合眾的。
所以我在事件中作了,效果還是可以,只不過這樣的循環感覺不是很好,還有注意你要在repeater數據邦定后再來做如上操作,否則沒效果的。。。。
轉載于:https://www.cnblogs.com/Longkin/archive/2008/05/16/1200238.html
總結
以上是生活随笔為你收集整理的获取repeater控件模版列中的控件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Ethernet帧结构
- 下一篇: Delphi 2009 之 TCateg