R – Server controls in an asp.net repeater

asp.netrepeaterservercontrols

Seems like I've ran into a wall here. I want some datasource to be bound to an asp.net repeater (well, doesn't have to be a repeater, but it seems like that's what I want). Now, here's the catch: I also need some server-controls inside that repeater for updating the data (TextBox'es and buttons).

To my understanding, this aint really possible to do in an orderly manner? I can't just add a textbox to the itemtemplate, and then fetch it later on in the code-behind it seems. At least not easily. Are there any known techniques for this kind of problem?

I can't use a gridview, since the data needs to be formatted in a certain way.

Best Answer

If you don't want to use an ItemCommand and want to just loop through the Repeater's items collection, so you have one "save" button at the bottom of the page, you can do it like this:

foreach(RepeaterItem itm in MyRepeater.Items)
{
     TextBox t = (TextBox)(itm.FindControl("TextBox1"));
     // do something with it.

}

Of course, you'll need to make sure that the TextBox1 in the ASPX has the Runat="Server" attribute.

Related Topic