Asp:Repeater and Asp:TextBox controls

K

Kelly Leahy

I'm using an Asp:Repeater control with a text box in the
item templates. This is for a system that has a number
of items that the user can edit and I'd like to generate
them based on a list. However, when the user clicks a
save button (not in the asp:repeater, but on the form
itself) I would like to (on postback) update the values
in the database and redisplay the page.

I can't figure out how to reference the controls
generated by the asp:repeater's template once they get
onto the rendered page. Is there any easy way to do
this? I must be missing something - I think.

Thanks,
Kelly
 
C

Craig Deelsnyder

Kelly said:
I can't figure out how to reference the controls
generated by the asp:repeater's template once they get
onto the rendered page. Is there any easy way to do
this? I must be missing something - I think.

Thanks,
Kelly

Control.FindControl('controlid') is what you're looking for. So you
could try myPage.FindControl, but in this case, you need to remember
that FindControl only looks in the current naming container. Inner
naming containers (or children if you want) are not searched. Here's a
list of naming containers/controls:

http://msdn.microsoft.com/library/d...rlrfsystemwebuiinamingcontainerclasstopic.asp

Notice that the Repeater and RepeaterItem are both naming containers.
Meaning if I did a myPage.FindControl(...) I could only search for the
Repeater's ID, not any of the items, etc., as they're inside another
naming container...a confusing concept at first, but useful background
info to help understand where FindControl looks, cuz it will look inside
other .NET controls on the page, if they are not a naming container
(asp:table is one example).

Soooo, once you have a reference to one of the repeater's items (whether
you loop over them, or do it in an item event), if you do
aRepeaterItem.FindControl('myControlId') you'll get a reference to it.
Where myControlId is the ID you gave the control in the template.

HTH
 
K

Kelly Leahy

Soooo, once you have a reference to one of the
repeater's items (whether
you loop over them, or do it in an item event), if you do
aRepeaterItem.FindControl('myControlId') you'll get a reference to it.
Where myControlId is the ID you gave the control in the
template.

Thanks. That's a good start. However, is there any way
I can make it easy to figure out which one I'm referring
to? Basically, I need to know which record it represents
in the database, so I know which one to update (since
each row is a different record in the database). Should
I just use custom attributes for this, or is there a
better way?

Kelly
 
C

Craig Deelsnyder

Kelly said:
Thanks. That's a good start. However, is there any way
I can make it easy to figure out which one I'm referring
to? Basically, I need to know which record it represents
in the database, so I know which one to update (since
each row is a different record in the database). Should
I just use custom attributes for this, or is there a
better way?

Kelly

Are there some key values for each item? If so, you should store those
in the items themselves, in hidden fields so when you are on that item,
you can grab those keys as well.

I believe there is a way to update the datasource and then accept the
changes into the datasource and commit them back to the database, but
I'm not familiar with that....
 

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

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,161
Latest member
GertrudeMa
Top