Selecting a value in dropdownlist in asp.net, vb.net is code behind
<p>I have a dropdownlist populating list of values in it in page_load .</p>

<p>I want to select a specific value </p>

<pre><code>Me.DropDownList_LocalOfficeAssignment.SelectedValue = ct.LocalOfficeName
Me.DropDownList_LocalOfficeAssignment has list of values.
</code></pre>

<p>Problem is: It always pointing to first item.</p>

<p>i tried this </p>

<pre><code>For Each item As ListItem In Me.DropDownList_LocalOfficeAssignment.Items
    If item.Equals(ct.LocalOfficeName) Then
        item.Selected = True
        Exit For
    End If
Next
DV.Dispose()
</code></pre>

<p>still pointing to the first item. i debugged, it should point to the last item.
ct.localoffice is containing the last item in the list. This is how i am populating the dropdown : </p>

<pre><code>Dim DV As DataView = New DataView(CacheVariable.States.Tables(0))
Dim DRV As DataRowView
Me.DropDownList_LocalOfficeAssignment.Items.Clear()
DV = New DataView(CacheVariable.LocalOffice.Tables(0))
If DV.Count &gt; 0 Then
    For Each DRV In DV
        Me.DropDownList_LocalOfficeAssignment.Items.Add(New ListItem(DRV("Name"), DRV("LocalOfficeID").ToString))
    Next
End If
</code></pre>
