Getting reference to controls within ItemTemplate in a repeater

A

AC [MVP MOSS]

I have a repeater with a header, footer, and item template. The item
template is the only one with server controls (hyperlinks, labels, and a
nested repeater). Within the top repeater, I'm handling the ItemDataBound
method in the code behind. In this handler, I need to get access to the
controls within the ItemTemplate.... however I've only found one way to do
this (and i"m not sure why it works).

Once I cast the sender (first param passed in my the ItemDataBound
handler) as a repeater, I see it has two items in the Controls property.
If I grab a reference to the second one, I can then use FindControls() to
get references to my labels, hyperlinks, and nested repeater in the item
template.

The thing that's confusing me: I can't figure out what is Control[0] and
Control[1] in the repeater. I know that the second one (Control[1]) gives
me what I need, just don't like the fact I don't know what it is. Checking
the ID of the control only yields a generic ID (ctr01 or something like
that).

Ideas?

TIA,
 
B

bruce barker

instead of the sender, you should be looking at the RepeaterItemEventArgs.

if (e.Item.ItemType == ListItemType.Item)
{
// reg template
}
else if (e.Item.ItemType == ListItemType.AlternateItem)
{
// alt template
}

-- bruce (sqlwork.com)
 
A

AC [MVP MOSS]

Duh... thanks bruce. I know I had done this before (a long, long time ago)
and couldn't realize why it was so hard this time... thanks!

--
-AC [MVP MOSS]
www.andrewconnell.com/blog


bruce said:
instead of the sender, you should be looking at the
RepeaterItemEventArgs.

if (e.Item.ItemType == ListItemType.Item)
{
// reg template
}
else if (e.Item.ItemType == ListItemType.AlternateItem)
{
// alt template
}

-- bruce (sqlwork.com)
I have a repeater with a header, footer, and item template. The item
template is the only one with server controls (hyperlinks, labels, and
a nested repeater). Within the top repeater, I'm handling the
ItemDataBound method in the code behind. In this handler, I need to
get access to the controls within the ItemTemplate.... however I've
only found one way to do this (and i"m not sure why it works).

Once I cast the sender (first param passed in my the ItemDataBound
handler) as a repeater, I see it has two items in the Controls
property. If I grab a reference to the second one, I can then use
FindControls() to get references to my labels, hyperlinks, and nested
repeater in the item template.

The thing that's confusing me: I can't figure out what is Control[0]
and Control[1] in the repeater. I know that the second one
(Control[1]) gives me what I need, just don't like the fact I don't
know what it is. Checking the ID of the control only yields a generic
ID (ctr01 or something like that).

Ideas?

TIA,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top