I have a UserControl, containing a FormView, containing a DropDownList. The FormView is bound to a data control.
Like so:
It is working for me with the OnDataBound event instead of OnDataBinding which occurs before the control is created.
Code-behind:
Protected Sub ddlCountry_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ddlCountry As New DropDownList
Dim strCountry As String = String.Empty
Dim lstItemToFind As New ListItem
ddlCountry = FormViewUsers.FindControl("ddlCountry")
strCountry = Eval("country")
lstItemToFind = ddlCountry.Items.FindByValue(strCountry)
If (Not IsNothing(lstItemToFind)) Then
ddlCountry.SelectedValue = strCountry
End If
End Sub
If you use this on other templates than the Edit you just need to validate:
If (FormViewUsers.CurrentMode = FormViewMode.Edit) Then
End If