title: ASP.net dropdown value help
body: <p>Hey all, i am in need of some help trying to figure out why this dropdown is not selecting the value after i pick one.</p>
  
  <p>Here is the ASP.net for the dropdown part:</p>
  
  <pre><code> &lt;div id="divItemsPerPage" runat="server" style="font-size:60%;font-weight:bolder;padding-right:15px;"&gt;
       Items per Page:
         &lt;asp:DropDownList ID="ddlPerPage" runat="server" AutoPostBack="true"&gt;
                  &lt;asp:ListItem Text="10" Value="10" /&gt;
                  &lt;asp:ListItem Text="25" Value="25" Selected="True" /&gt;
                  &lt;asp:ListItem Text="50" Value="50" /&gt;
                  &lt;asp:ListItem Text="100" Value="100" /&gt;
         &lt;/asp:DropDownList&gt;
   &lt;/div&gt;
  </code></pre>
  
  <p>and this is my codebehind:</p>
  
  <pre><code> Private Sub ddlPerPage_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlPerPage.SelectedIndexChanged
          'LoadFromViewstate()
          _rowsPerPage = Convert.ToInt32(ddlPerPage.SelectedItem.Value)
          gvData.PageIndex = 0
          SaveRowsCountToCookie(_rowsPerPage)
   End Sub
  
   Public Property RowsPerPage() As Integer
          Get
              Return Utils.cleanInt(ddlPerPage.SelectedValue)
          End Get
          Set(ByVal value As Integer)
              Dim itmX As New ListItem(value.ToString, value.ToString)
  
              ddlPerPage.SelectedIndex = -1
              If ddlPerPage.Items.Contains(itmX) Then
                  ddlPerPage.Items.FindByValue(value.ToString).Selected = True
              Else
                  ddlPerPage.SelectedIndex = -1
                  For i As Integer = 0 To ddlPerPage.Items.Count - 1
                      If Utils.cleanInt(ddlPerPage.Items(i).Value) &gt; value Then
                          ddlPerPage.Items.Insert(i, itmX)
                          ddlPerPage.SelectedIndex = i
                          Exit For
                      End If
                  Next
              End If
              _rowsPerPage = value
              ViewState("RowsPerPage") = _rowsPerPage
          End Set
      End Property
  </code></pre>
  
  <p>No matter what i select it still has the same value as when the page started. The <strong>_rowsPerPage = value</strong> always seems to be the same.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Ok, looking at it more closely it seems that <strong>Convert.ToInt32(ddlPerPage.SelectedItem.Value)</strong> never has the correct value when i select a number??</p>
  
  <p>Any help would be great! :o)</p>
  
  <p>David</p>