0
votes

I want to give a value to a control in asp.net repeater footer template.

Dim FooterTemplate As Control = TicketRepeater.Controls(TicketRepeater.Controls.Count - 1).Controls(0)
Dim lblFooter As Literal = TryCast(FooterTemplate.FindControl("TicketTotalNumberOfTickets"), Literal)
lblFooter.Text = TicketDataTable.Rows.Count.ToString()

Return with error:

Specified argument was out of the range of valid values.
Parameter name: index

AFAIU it cant find count of controls = no controls found?. Any suggestions?

Check points:

  • all ID's are correct
  • repeater has 3 part headertemplate, itemtemplate, footertemplate

Help!


Update

The code actually work after databind(). Any ideas how to make it work before databind event?

1

1 Answers

1
votes

It can't be done before databind. Until you bind that repeater to something, it's just an empty shell and has no controls. Binding is what creates the header, footer, and items.

Binding would wipe away anything to do with the footer, anyway, so if you intend to bind to that repeater (and why else use one?) there's no point in trying to manipulate it before you bind to it.

If what you want is to have an empty repeater with header and footer and later (perhaps after some action by the user) bind to a populated data source, you can try binding to an empty (but not null) data source. I'm not 100% sure, but I think that should produce a header and footer in your repeater but no items.