title: Accessing Textboxes in Repeater Control
body: <p>All the ways I can think to do this seem very hackish.  What is the right way to do this, or at least most common?</p>
  
  <p>I am retrieving a set of images from a LINQ-to-SQL query and databinding it and some other data to a repeater.  I need to add a textbox to each item in the repeater that will let the user change the title of each image, very similar to Flickr.</p>
  
  <p><strong>How do I access the textboxes in the repeater control and know which image that textbox belongs to?</strong></p>
  
  <p>Here is what the repeater control would look like, with a submit button which would update all the image rows in Linq-to-SQL:</p>
  
  <p><a href="http://casonclagg.com/layout.jpg">alt text http://casonclagg.com/layout.jpg</a></p>
  
  <p><strong>Edit:</strong></p>
  
  <p><strong>This code works</strong></p>
  
  <p>Just make sure you don't blow your values away by Binding outside of if(!Page.IsPostBack) like me.. Oops.</p>
  
  <pre><code>&lt;asp:Repeater ID="Repeater1" runat="server"&gt;
      &lt;ItemTemplate&gt;
          &lt;div class="itemBox"&gt;
              &lt;div class="imgclass"&gt;
                  &lt;a title='&lt;%# Eval("Name") %&gt;' href='&lt;%# Eval("Path") %&gt;' rel="gallery"&gt;
                      &lt;img alt='&lt;%# Eval("Name") %&gt;' src='&lt;%# Eval("Path") %&gt;' width="260" /&gt;
                  &lt;/a&gt;
              &lt;/div&gt;
              &lt;asp:TextBox ID="TextBox1" Width="230px" runat="server"&gt;&lt;/asp:TextBox&gt;
          &lt;/div&gt;
      &lt;/ItemTemplate&gt;
  &lt;/asp:Repeater&gt;
  </code></pre>
  
  <p>And Submit Click:</p>
  
  <pre><code>protected void Button1_Click(object sender, EventArgs e)
  {
      foreach (RepeaterItem item in Repeater1.Items)
      {
          TextBox txtName = (TextBox)item.FindControl("TextBox1");
          if (txtName != null)
          {
              string val = txtName.Text;
              //do something with val
          }
      }
  }
  </code></pre>