title: listview item said to be "Null"
body: <p>I have a list view which is below.....
  <a href="https://i.stack.imgur.com/ZLvyO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZLvyO.png" alt="enter image description here" /></a></p>
  <p>I am trying to read the <strong>Quantity</strong> and <strong>Available</strong> based on their <strong>ProductID</strong></p>
  <p>I want to read the data in the listview and then i will view the error if <code>Quantity &gt; Available</code></p>
  <p>Now when ever i do so, the items are <em>Null</em></p>
  <p><strong>here is ASPnet:</strong></p>
  <pre><code>&lt;asp:ListView ID=&quot;lvCart&quot; runat=&quot;server&quot; onitemcommand=&quot;lvCart_ItemCommand&quot;&gt;
      &lt;ItemTemplate&gt;
      &lt;tr&gt;
      &lt;td&gt;
           &lt;asp:Label ID=&quot;lbproductid&quot; runat=&quot;server&quot;
              class=&quot;form-control&quot; Width=&quot;50&quot;
              Text='&lt;%# Eval(&quot;ProductID&quot;) %&gt;' /&gt;
      &lt;/td&gt;
      &lt;td&gt;
          &lt;%# Eval(&quot;Name&quot;) %&gt;
          &lt;asp:Literal ID=&quot;ltRefNo&quot; runat=&quot;server&quot;
              Text='&lt;%# Eval(&quot;RefNo&quot;) %&gt;' Visible=&quot;false&quot; /&gt;
      &lt;/td&gt;
      &lt;td&gt;
          Php &lt;%# Eval(&quot;Price&quot;, &quot;{0: #,###.00}&quot;) %&gt;
      &lt;/td&gt;
      &lt;td&gt;
          &lt;asp:TextBox ID=&quot;txtQty&quot; runat=&quot;server&quot;
              class=&quot;form-control&quot; type=&quot;number&quot;
              min=&quot;1&quot; max=&quot;99&quot; MaxLength=&quot;2&quot; Width=&quot;70&quot;
              Text='&lt;%# Eval(&quot;Quantity&quot;) %&gt;' required /&gt;
  
              &lt;asp:Label ID=&quot;avail&quot; runat=&quot;server&quot;
              class=&quot;form-control&quot; Width=&quot;50&quot;
              Text='&lt;%# Eval(&quot;Available&quot;) %&gt;' /&gt;
      &lt;/td&gt;
  </code></pre>
  <p><strong>Code Behind 1:</strong>
  (here is what i tried)</p>
  <pre><code>void getavail()
  {
      Label lbproductid = (Label)lvCart.FindControl(&quot;lbproductid&quot;);
      Label avail = (Label)lvCart.FindControl(&quot;avail&quot;);
      //ITemplate ID = (ITemplate)lvCart.FindControl(&quot;ProductID&quot;);
      TextBox txtQty = (TextBox)lvCart.FindControl(&quot;txtQty&quot;);
  
      if (int.Parse(txtQty.Text) &gt; int.Parse(avail.Text))
      {
          error.Visible = true;
      }
      con.Close();
   }
  </code></pre>
  <p><strong>Code behind 2:</strong>
  (Second trial)</p>
  <pre><code>foreach (ListViewDataItem dataitem in lvCart.Items)
  {
      Label lbproductid = (Label)lvCart.FindControl(&quot;lbproductid&quot;);
      Label avail = (Label)lvCart.FindControl(&quot;avail&quot;);
      //ITemplate ID = (ITemplate)lvCart.FindControl(&quot;ProductID&quot;);
      TextBox txtQty = (TextBox)lvCart.FindControl(&quot;txtQty&quot;);
  
      if (int.Parse(txtQty.Text) &gt; int.Parse(avail.Text))
      {
          error.Visible = true;
      }
      con.Close();
  }
  </code></pre>
  <p>When trying the second codes, it does not read codes after it. Starting at the line:</p>
  <pre><code>Label lbproductid = (Label)lvCart.FindControl(&quot;lbproductid&quot;); 
  </code></pre>
  <p>and then it directs to last bracket and <em>close();</em></p>
  <p>I am putting this GetAvail in the page load event as i want it to show right away.</p>
  <p>help this got me hours. thanks in advance</p>