title: ASP.NET DropDownList posting ""
body: <p>I am using ASP.NET forms version 3.5 in VB</p>
  
  <p>I have a dropdownlist that is filled with data from a DB with a list of countries</p>
  
  <p>The code for the dropdown list is</p>
  
  <pre><code>         &lt;label class="ob_label"&gt;
              &lt;asp:DropDownList ID="lstCountry" runat="server" CssClass="ob_forminput"&gt;
              &lt;/asp:DropDownList&gt;
           Country*&lt;/label&gt;
  </code></pre>
  
  <p>And the code that the list is</p>
  
  <pre><code> Dim selectSQL As String = "exec dbo.*******************"
  
      ' Define the ADO.NET objects.
      Dim con As New SqlConnection(connectionString)
      Dim cmd As New SqlCommand(selectSQL, con)
      Dim reader As SqlDataReader
  
      ' Try to open database and read information.
      Try
          con.Open()
          reader = cmd.ExecuteReader()
  
          ' For each item, add the author name to the displayed
          ' list box text, and store the unique ID in the Value property.
  
          Do While reader.Read()
              Dim newItem As New ListItem()
              newItem.Text = reader("AllSites_Countries_Name")
              newItem.Value = reader("AllSites_Countries_Id")
              CType(LoginViewCart.FindControl("lstCountry"), DropDownList).Items.Add(newItem)
          Loop
          reader.Close()
  
          CType(LoginViewCart.FindControl("lstCountry"), DropDownList).SelectedValue = 182
  
      Catch Err As Exception
          Response.Redirect("~/error-on-page/")
  
          MailSender.SendMailMessage("*********************", "", "", OrangeBoxSiteId.SiteName &amp; " Error Catcher", "&lt;p&gt;Error in sub FillCountry&lt;/p&gt;&lt;p&gt;Error on page:" &amp; HttpContext.Current.Request.Url.AbsoluteUri &amp; "&lt;/p&gt;&lt;p&gt;Error details: " &amp; Err.Message &amp; "&lt;/p&gt;")
          Response.Redirect("~/error-on-page/")
      Finally
          con.Close()
      End Try
  </code></pre>
  
  <p>When the form is submitted an error occurs which says that the string "" cannot be converted to the datatype integer. For some reason the dropdownlist is posting "" rather than the value for the selected country.</p>