title: ASP.NET: How to access repeater generated form input elements?
body: <p>i'm want to have a repeater generate a bunch of checkboxes, e.g.:</p>
  
  <pre><code>&lt;tr&gt;&lt;td&gt;&lt;input type="checkbox" name="t" value="11cbf4deb87" /&gt; &lt;input type="checkbox" name="a" value="33cbf4deb87" /&gt;stackoverflow.com&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;input type="checkbox" name="t" value="11cbf4deb88" /&gt; &lt;input type="checkbox" name="a" value="33cbf4deb87" /&gt;microsoft.com&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;input type="checkbox" name="t" value="11cd3f33a89" /&gt; &lt;input type="checkbox" name="a" value="33cbf4deb87" /&gt;gmail.com&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;input type="checkbox" name="t" value="1138fecd337" /&gt; &lt;input type="checkbox" name="a" value="33cbf4deb87" /&gt;youporn.com&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;input type="checkbox" name="t" value="11009efdacc" /&gt; &lt;input type="checkbox" name="a" value="33bf4deb87" /&gt;fantasti.cc&lt;/td&gt;&lt;/tr&gt;
  </code></pre>
  
  <p>Question 1: How do i individually reference each checkbox when the repeater is running so i can set the unique value?</p>
  
  <p>Do i data-bind it with something like:</p>
  
  <pre><code>&lt;itemtemplate&gt;
     &lt;tr&gt;
        &lt;td&gt;
           &lt;input type="checkbox" name="t" 
              value="&lt;%# ((Item)Container.DataItem).TangoUniquifier %&gt;" /&gt;
           &lt;input type="checkbox" name="a" 
              value="&lt;%# ((Item)Container.DataItem).AlphaUniquifier %&gt;" /&gt;
           &lt;%# ((Item)Container.DataItem).SiteName %&gt;
        &lt;/td&gt;
     &lt;/tr&gt;
  &lt;/itemtemplate&gt;
  </code></pre>
  
  <p>Or am i supposed to set it somehow in the OnItemDataBound?</p>
  
  <pre><code>&lt;asp:repeater id="ItemsRepeater" 
        OnItemDataBound="ItemsRepeater_OnItemDataBound" runat="server"&gt;
     ...
     &lt;itemtemplate&gt;
        &lt;tr&gt;
           &lt;td&gt;
              &lt;input id="chkTango" type="checkbox" name="t" runat="server" /&gt;
              &lt;input id="chkAlpha" type="checkbox" name="a" runat="server" /&gt;
              &lt;%# ((Item)Container.DataItem).SiteName %&gt;
           &lt;/td&gt;
        &lt;/tr&gt;
     &lt;/itemtemplate&gt;
     ...
  &lt;/asp:repeater&gt;
  
  
  protected void ItemsRepeater_OnItemDataBound(object sender, RepeaterItemEventArgs e)
  {
     // if the data bound item is an item or alternating item (not the header etc)
     if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
     {
        // get the associated item
        Item item = (Item)e.Item.DataItem;
  
        //???
        this.chkTango.Value = item.TangoUniquifier;
        this.chkAlpha.Value = item.AlphaUniquifier;
     }
  }
  </code></pre>
  
  <p>But if i'm supposed to reference it in the code-behind, how do i reference it in the code-behind?   Am i supposed to reference it using the (server-side) id property of an <code>&lt;INPUT&gt;</code> control? i realize that the ID of a control on the server-side is not the same as the ID that will be present on the client.</p>
  
  <p>Or do i have to do something where i have to find an INPUT control with a name of "t" and another with a name of "a"? And what kind of control is a CheckBox that allows me to set it's input value?</p>
  
  <pre><code>protected void ItemsRepeater_OnItemDataBound(object sender, RepeaterItemEventArgs e)
  {
     // if the data bound item is an item or alternating item (not the header etc)
     if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
     {
        // get the associated item
        Item item = (Item)e.Item.DataItem;
  
        CheckBox chkTango = (CheckBox)e.Item.FindControl("chkTango");
        chkTango.Value = item.TangoUniquifier;
  
        CheckBox chkAlpha = (CheckBox)e.Item.FindControl("chkAlpha");
        chkAlpha.Value = item.AlphaUniquifier;
     }
  }
  </code></pre>
  
  <hr>
  
  <p>Question 2:
  When the user later clicks SUBMIT, how do i find all the checked checkboxes, or more specifically their VALUES?</p>
  
  <p>Do i have to FindControl?</p>
  
  <pre><code>protected void DoStuffWithLinks_Click(object sender, EventArgs e)
  {
     // loop through the repeater items
     foreach (RepeaterItem repeaterItem in actionItemRepeater.Items)
     {
        Item item = repeaterItem.DataItem as Item;
  
        // grab the checkboxes
        CheckBox chkAlpha = (CheckBox)repeaterItem.FindControl("chkAlpha");
        CheckBox chkTango = (CheckBox)repeaterItem.FindControl("chkTango");
  
        if (chkAlpha.Checked)
        {          
           item.DoAlphaStuff(chkAlpha.Name);
        }
  
        if (chkTango.Checked)
        {
           item.DoTangoStuff(chkTango.Name);
        }
     }
  }
  </code></pre>
  
  <p>Is the repeater items DataItem still there on a click event handler?</p>