프로그래밍/ASP.NET

Repeater 에서 Header / Footer 템플릿 아이템 찾기 (리피터 FindContorl)

쇠주는참이슬 2012. 4. 25. 11:14

Repeater 에서 Header / Footer 템플릿 아이템 찾기 (리피터 FindContorl) 



To find a control in the header:

lblControl = repeater1.Controls[0].Controls[0].FindControl("lblControl");

To find a control in the footer:

lblControl = repeater1.Controls[repeater1.Controls.Count - 1].Controls[0].FindControl("lblControl");

With extension methods

public static class RepeaterExtensionMethods
{
   
public static Control FindControlInHeader(this Repeater repeater, string controlName)
   
{
       
return repeater.Controls[0].Controls[0].FindControl(controlName);
   
}

   
public static Control FindControlInFooter(this Repeater repeater, string controlName)
   
{
       
return repeater.Controls[repeater.Controls.Count - 1].Controls[0].FindControl(controlName);
   
}
}