Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alan Silver - 18 Jul 2005 18:58 GMT
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.

Signature

Alan Silver
(anything added below this line is nothing to do with me)

Curt_C [MVP] - 18 Jul 2005 20:18 GMT
> Hello,
>
[quoted text clipped - 12 lines]
>
> 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.

Signature

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

Jacek Stawicki - 18 Jul 2005 21:15 GMT
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;
            }
         }
         

Signature

C# Dev

> > Hello,
> >
[quoted text clipped - 17 lines]
> think it's 0 like you indicated, but see whats in rptNpVars.Controls[0]
> by stepping into it in the watch window.
Alan Silver - 18 Jul 2005 23:18 GMT
>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:
>
[quoted text clipped - 4 lines]
>             }
>          }

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.

Signature

Alan Silver
(anything added below this line is nothing to do with me)

Alan Silver - 18 Jul 2005 23:16 GMT
>>  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
[quoted text clipped - 11 lines]
>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.

Signature

Alan Silver
(anything added below this line is nothing to do with me)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.