title: Why is count not accurate?
body: <p>Here's the idea: the user can add items and they populate in a listbox control. If the user has no items, they should not be able to submit the form. However, I add an artificial item when there are no items using:</p>
  
  <pre><code>if (ds.Tables[0].Rows.Count == 0)
  {
      lstItems.Items.Insert(0, "No items have been added.");
  }
  else
  {
      lstItems.DataSource = ds;
      lstItems.DataTextField = "ItemInfo";
      lstItems.DataValueField = "Item_ID";
      lstItems.DataBind();
  }
  </code></pre>
  
  <p>Later, I want to ensure there are items before submitting, but the DataSet (<code>ds</code>) is not available in that function/context. To resolve this, I declared a global variable (public int) within the class that could be referenced:</p>
  
  <pre><code>public int numItems = 0;
  </code></pre>
  
  <p>Then set it like so:</p>
  
  <pre><code>numItems = ds.Tables[0].Rows.Count;
  </code></pre>
  
  <p>That way it wouldn't be thrown off by the one artificial record I inserted in <code>lstItems</code>. However, this isn't working. The value remains 0, even thought the above conditional statement evaluates correctly indicating that the row count is <em>not</em> 0. What am I doing wrong? Is there a better way of doing this? I considered using:</p>
  
  <pre><code>if (lstItems.Items.Count &lt; 1)
  {
      // allow submission
  }
  </code></pre>
  
  <p>But the problem with this is that it hits off my artificial item:</p>
  
  <pre><code>lstItems.Items.Insert(0, "No items have been added.");
  </code></pre>
  
  <p>So what is the best way to check if there are any user-created items in the list?</p>