.NET     Console.WriteLine( "All Things .NET" );
.NET Nerd Blog Home
8.01.2005

 
Access Controls in Repeater Header / Footer
Took me a bit to discover this by trial & error today. The controls (labels, text box, etc) that are in a Repeater header and footer template are not automagically bound to code-behind class member variables like regular page controls are.

Instead, you can "find" them at runtime like this (note: if you are data binding the repeater control, this must be AFTER call to DataBind).

Label lblErrorHead = repErrors.Controls[0].FindControl( "lblErrorHead" ) as Label;

Not sure about relying on the Controls[0] like above. In my case, the items laid out like this:
  1. HeaderItem (element 0)
  2. Item (element 1)
  3. FooterItem (element 2)
For uber-safe code, you should probably find the HeaderItem by iterating the controls and looking at the ItemType.

I suppose another way to handle all this would be to handle the ItemCreated or ItemDataBound events, where you'll get a call for the Header and Footer items.


Comments: Post a Comment

Powered by Blogger