473,396 Members | 2,059 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,396 software developers and data experts.

How do I get at a control in the header template of a repeater?

Hello,

If I have a control in the header template of a repeater, how do I get
at this in code? I know how to do this for an ItemTemplate, you just
do...

txtFred = (TextBox)rptNpVars.Items[i].FindControl("txtFred");

where i is the index of the item. How do I do a similar thing for the
header? Following a post I found in the archives, I tried ...

txtFred = (TextBox)rptNpVars.Controls[0].FindControl("txtFred");

but this gave an error "Specified argument was out of the range of valid
values. Parameter name: index".

Thanks for any help.

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #1
4 1818
Alan Silver wrote:
Hello,

If I have a control in the header template of a repeater, how do I get
at this in code? I know how to do this for an ItemTemplate, you just do...

txtFred = (TextBox)rptNpVars.Items[i].FindControl("txtFred");

where i is the index of the item. How do I do a similar thing for the
header? Following a post I found in the archives, I tried ...

txtFred = (TextBox)rptNpVars.Controls[0].FindControl("txtFred");

but this gave an error "Specified argument was out of the range of valid
values. Parameter name: index".

Thanks for any help.


Have you tried the QuickWatch window on rptNpVars.Controls and seeing
what's in it? I dont know the index for the header template but I would
think it's 0 like you indicated, but see whats in rptNpVars.Controls[0]
by stepping into it in the watch window.

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com
Nov 19 '05 #2
I'm not sure, but I think this index is -1. Just try :)

Another way is to use:

void R1_ItemDataBound(Object Sender, RepeaterItemEventArgs e) {
if (e.Item.ItemType == ListItemType.Header) {

// txtFred = ((TextBox)e.Item.FindControl("txtFred")).Text;
}
}
--
C# Dev
"Curt_C [MVP]" wrote:
Alan Silver wrote:
Hello,

If I have a control in the header template of a repeater, how do I get
at this in code? I know how to do this for an ItemTemplate, you just do...

txtFred = (TextBox)rptNpVars.Items[i].FindControl("txtFred");

where i is the index of the item. How do I do a similar thing for the
header? Following a post I found in the archives, I tried ...

txtFred = (TextBox)rptNpVars.Controls[0].FindControl("txtFred");

but this gave an error "Specified argument was out of the range of valid
values. Parameter name: index".

Thanks for any help.


Have you tried the QuickWatch window on rptNpVars.Controls and seeing
what's in it? I dont know the index for the header template but I would
think it's 0 like you indicated, but see whats in rptNpVars.Controls[0]
by stepping into it in the watch window.

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

Nov 19 '05 #3
>> If I have a control in the header template of a repeater, how do I
get at this in code? I know how to do this for an ItemTemplate, you
just do...
txtFred = (TextBox)rptNpVars.Items[i].FindControl("txtFred");
where i is the index of the item. How do I do a similar thing for
the header? Following a post I found in the archives, I tried ...
txtFred = (TextBox)rptNpVars.Controls[0].FindControl("txtFred");
but this gave an error "Specified argument was out of the range of
valid values. Parameter name: index".
Thanks for any help.


Have you tried the QuickWatch window on rptNpVars.Controls and seeing
what's in it? I dont know the index for the header template but I would
think it's 0 like you indicated, but see whats in rptNpVars.Controls[0]
by stepping into it in the watch window.


I'm not using VS, so I can't do this. I'm fairly new at ASP.NET and
didn't fancy spending all that money on VS 2003, when it's about to be
superseded by an apparently superior product.

Also, I find I learn what's going on a lot better by doing it all by
hand. I get to see what is needed first hand, rather than having an IDE
make changes without me knowing. I think I've learnt a lot more this way
than I would have with VS.

Thanks anyway.

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #4
>I'm not sure, but I think this index is -1. Just try :)

OK, I'll give it a go (on my way to bed, so I'm not trying it now!!).
Another way is to use:

void R1_ItemDataBound(Object Sender, RepeaterItemEventArgs e) {
if (e.Item.ItemType == ListItemType.Header) {

// txtFred = ((TextBox)e.Item.FindControl("txtFred")).Text;
}
}


Which is fine inside the event, but what if you want to get at it
outside of that? In truth, I suspect that you wouldn't want it inside
the repeater then, but it's too late for my little brain to think this
through!!

Thanks for the reply.

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #5

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

Similar topics

0
by: Nilesh W | last post by:
Hi I am using data repeater in my application to display data. Header template for data repeater I want add at run time because the header text for item columns read from some other resources ...
3
by: Neil Zanella | last post by:
Hello, I have a bunch of HTML input controls which I need to generate from within a for loop. I would like them to have id attributes set to values foo1, foo2, foo3, foo4, etc... ...
1
by: Steve Franks | last post by:
OK this is driving me nuts - hope someone can help. I am searching for a way to dynamically output a value within the HeaderTemplate section of a Repeater control. Is this possible? It is...
5
by: serge calderara | last post by:
Dear all, I am new in asp.net and prepare myself for exam I still have dificulties to understand the difference between server control and HTML control. Okey things whcih are clear are the fact...
0
by: kris | last post by:
Hi All , I am using a repeater control to display set of records. Now on the header template of the Reapeter control there is a Check Box . For each record that will displayed there will be a...
4
by: sck10 | last post by:
Hello, I have a repeater that is bound to a SQL Server table. I would like to place a summary in the footer for the item count and product cost. I have two fields. One for the product name...
8
by: fernandezr | last post by:
I would like to use a user control as a template inside a repeater. Some of the fields in the control should be hidden depending on whether or not there is data. I'm still a ASP .Net newbie so the...
2
by: Simit Kulkarni | last post by:
Hi All, I am stucked with a problem , regarding Repeater Controls Header Template. I want to show a Image Button in the Header Template of a Repeater Control and on the Click of...
3
by: Emma Middlebrook | last post by:
Hi there, I've been trying to implement a repeater control in an ASP.NET 2 page but I can't seem to get the layout exactly how I want and I'm not sure if it's something that I am doing wrong or...
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.