That's a bit tricky outside of the ItemCreated/ItemDataBound event handlers. What you need to do is explore the inner control hierarchy of the grid. If you grid does not use paging then footer can be located using:
I personally prefer not to rely on knowledge of design time setup so suggest you loop through the DataGrid1.Controls(0).Controls collection, type each element to DataGridItem and check its ItemType - terminate the loop when you get to Footer type. For efficiency,
loop backwards starting from the last control in a collection
Yir got this to work, but it only shows the value then the site it loaded the first time, after a postback the value is not updated in my label. Is the ItemCreated event only done one time or ? and not on every postback, from another control
No need got it to work, just needed to have my veriable in a Session so it wasnt set to 0 again and again :) thx for all the help, u guys are life savers :D
mimo
Member
102 Points
26 Posts
FindControl in Repeater FooterTemplate
Oct 11, 2005 12:22 PM|LINK
Bug_Bugger
All-Star
22605 Points
4505 Posts
Re: FindControl in Repeater FooterTemplate
Oct 11, 2005 12:53 PM|LINK
DataGrid1.Controls(0).Controls(DataGrid1.Controls(0).Controls.Count-1)
I personally prefer not to rely on knowledge of design time setup so suggest you loop through the DataGrid1.Controls(0).Controls collection, type each element to DataGridItem and check its ItemType - terminate the loop when you get to Footer type. For efficiency, loop backwards starting from the last control in a collection
Cheers
alvinz_c
Star
9972 Points
1981 Posts
Re: FindControl in Repeater FooterTemplate
Oct 11, 2005 01:02 PM|LINK
Hi, you can access through the ItemCreated/ItemDataBound event
protected void rpt_ItemCreated(Object sender, RepeaterItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Footer)
Label lbl = (Label)e.Item.FindControl("myLabel");
}
or
Label lbl = (Label)Repeater1.Controls[Repeater1.Controls.Count-1].FindControl("myLabel");
Hope this helps...
Microsoft ASP.NET™ Enthusiast v1.1 / v2.0, Malaysia
Blog : http://alvinzc.blogspot.com
mimo
Member
102 Points
26 Posts
Re: FindControl in Repeater FooterTemplate
Oct 11, 2005 01:18 PM|LINK
Yir got this to work, but it only shows the value then the site it loaded the first time, after a postback the value is not updated in my label. Is the ItemCreated event only done one time or ? and not on every postback, from another control
alvinz_c
Star
9972 Points
1981 Posts
Re: FindControl in Repeater FooterTemplate
Oct 11, 2005 01:45 PM|LINK
Microsoft ASP.NET™ Enthusiast v1.1 / v2.0, Malaysia
Blog : http://alvinzc.blogspot.com
mimo
Member
102 Points
26 Posts
Re: FindControl in Repeater FooterTemplate
Oct 11, 2005 01:55 PM|LINK