title: Capturing changed values from a Repeater on postback
body: <p>This is plaguing me and I've read countless solutions that all seem to be off a bit.  I have a repeater that has 2 drop downs per item and a few items.  These all have potential values 0-8 that the user can select and I want to gather the data on a postback when the user click a button on the bottom of the page.</p>
  
  <pre><code>    &lt;asp:Repeater ID="rptPricing" runat="server" OnItemDataBound="rptPricing_OnItemDataBound"&gt;
      &lt;ItemTemplate&gt;
          &lt;div class="Row clear"&gt;
              &lt;div class="Column Cat"&gt;&lt;%# ((Price)Container.DataItem).AgeCategory %&gt;&lt;/div&gt;
              &lt;div id="dWasPrice" runat="server" class="Column Was"&gt;
                  &lt;asp:Literal ID="litPreviousPrice" runat="server" /&gt;&lt;span class="strike"&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;div class="Column Now"&gt;$&lt;%# ((Price)Container.DataItem).FullPrice %&gt;&lt;/div&gt;
              &lt;div class="Column Deposit"&gt;
                  &lt;asp:DropDownList ID="ddlCountForPart" runat="server" skucode="&lt;%# ((Price)Container.DataItem).PartHeaderCode %&gt;"&gt;
                      &lt;asp:ListItem Text="0" Value="0"&gt;&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem Text="1" Value="1"&gt;&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem Text="2" Value="2"&gt;&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem Text="3" Value="3"&gt;&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem Text="4" Value="4"&gt;&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem Text="5" Value="5"&gt;&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem Text="6" Value="6"&gt;&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem Text="7" Value="7"&gt;&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem Text="8" Value="8"&gt;&lt;/asp:ListItem&gt;
                  &lt;/asp:DropDownList&gt;                        
              &lt;/div&gt;
              &lt;div class="Column Full"&gt;
                  &lt;asp:DropDownList ID="ddlCountForFull" runat="server" skucode="&lt;%# ((Price)Container.DataItem).FullHeaderCode %&gt;"&gt;
                      &lt;asp:ListItem Text="0" Value="0"&gt;&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem Text="1" Value="1"&gt;&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem Text="2" Value="2"&gt;&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem Text="3" Value="3"&gt;&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem Text="4" Value="4"&gt;&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem Text="5" Value="5"&gt;&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem Text="6" Value="6"&gt;&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem Text="7" Value="7"&gt;&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem Text="8" Value="8"&gt;&lt;/asp:ListItem&gt;
                  &lt;/asp:DropDownList&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/ItemTemplate&gt;
  &lt;/asp:Repeater&gt;
  </code></pre>
  
  <p>Here is the binding.</p>
  
  <pre><code>private void BindDetails()
  {
      SetDiscountContent();
  
      rptPricing.DataSource = _Detail.Prices;
      rptPricing.DataBind();
  }
  </code></pre>
  
  <p>Here is where the data is not present.</p>
  
  <pre><code>if ( IsPostBack &amp;&amp; UIControlUtil.GetPostBackControl(Page) == lnkAddToCart)
  {
      //populate the cart without javascript
      //find the drop down with items selected and create Order Elements
      try
      {
          var orders = new Order[0];
          foreach (RepeaterItem item in rptPricing.Items)
          {
              var dl = item.FindControl("ddlCountForFull");
              if (dl != null)
              {
                  Array.Resize(ref orders, orders.Length + 1);
                  orders[orders.Length - 1] = new Order() {
                      Quantity = Convert.ToInt32(dl.SelectedValue),
                      Sku = dl.Attributes["skucode"]};
  </code></pre>
  
  <p>I've tried moving the call to <code>BindDetails()</code> around from <code>PageLoad</code> to <code>OnInit</code> and also playing with the postback flag.  I have also played with the <code>ViewState</code> flags to no avail.</p>
  
  <p>EDIT (Adding Page Load), please note I have played with moving this to the OnInit.</p>
  
  <pre><code> protected void Page_Load(object sender, EventArgs e)
      {
  
          if (ContentItem == null) return;
  
          if (!IsPostBack)
          {
              var control = (ContentManagement.Library.Sitecore.PreDefinedControl)ContentItem;
              _Detail = (Details)control.DataElements[0];
              BindDetails();
          }
  
          if (ShoppingCartHelper.GetProductsOfTInCart&lt;blah&gt;() &gt; 8)
          {
              lnkAddToCart.Enabled = false;
              lnkAddToCart.CssClass = lnkAddToCart.CssClass + " disabled cartmax";
          }
      }
  </code></pre>