473,395 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Getting reference to controls within ItemTemplate in a repeater

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,

--
-AC [MVP MOSS]
www.andrewconnell.com/blog
Feb 13 '07 #1
2 2621
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)

AC [MVP MOSS] wrote:
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,
Feb 13 '07 #2
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 barker wrote:
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)

AC [MVP MOSS] wrote:
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,
Feb 13 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: theComputer7 | last post by:
I cut down the code to make this half way understandable... I have read Data Grid girls caution about over use of dynamic controls. I truly believe what I am doing requires dynamically inserted...
6
by: Tom Kaminski [MVP] | last post by:
On my code behind page, how can I reference a Label control that's included in a Repeater? In other words, given: <asp:Repeater id="Repeater1" runat="server"> <HeaderTemplate> <table> <tr>...
1
by: Josh | last post by:
I am trying to move some of my more common controls into user controls. However, I seem to have problems maintaining state of databound controls that are contained within user controls. On...
2
by: Tarun Mistry | last post by:
Hi everyone, a simple problem I hope you guys can help me with. I have a repeater control, within this i would like to place another server control. I.e. <asp:Repeater id="Repeater1"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.