title: Get the correct Value from HiddenField in ASP.NET Repeater
body: <p>after i look around and tried a couple of solution i decided to post.Bear in mind that i am learning asp atm ( so my experience is little ) </p>
  
  <p>So the issue is the following:</p>
  
  <p>I have an asp.net repeater pulling data from a database.
  I have a <code>HiddenField</code> where i store an <code>ID</code>.</p>
  
  <p>In the code behind i try to get that <code>ID</code> to a string but everything i tried it only returns me  a single ID which is 1.</p>
  
  <p>Asp code : </p>
  
  <pre><code>&lt;asp:Repeater runat="server" ID="dataRepeater" EnableTheming="true"&gt;
      &lt;ItemTemplate&gt;
  
          &lt;asp:HiddenField ID="prodID" runat="server" Value='&lt;%#Eval("ProductID")%&gt;' /&gt;
  
          &lt;asp:Button runat="server" ID="addToCart" Text="Add to cart" OnClick="Something" /&gt;
  
      &lt;/ItemTemplate&gt;
  &lt;/asp:Repeater&gt;  
  </code></pre>
  
  <p>C# code behind:</p>
  
  <pre class="lang-cs prettyprint-override"><code>dataRepeater.DataSource = dt;
  dataRepeater.DataBind();
  
  protected void Something(object sender, EventArgs e) {
   string pID = "";
  
   for (int i = 0; i &lt; dataRepeater.Items.Count; i++) {
    var item = dataRepeater.Items[i];
  
    var hf = item.FindControl("prodID") as HiddenField;
    pID = hf.Value;
   }
  }
  </code></pre>
  
  <p>As i tried the foreach alternative, the result in <code>pID</code> is the same 1, where it should be the <code>product ID</code> from the database. </p>
  
  <p>I am sure i did something wrong, but i can't figure it out what. 
  Thx for your time.</p>