Right, that explains a lot.
null is not a valid value in the DropDownList so you can't use that as a value for the SelectedValue property.
You should implement some code for the DataBound event of the DetailsView control. Inside that event handler, get a reference to the View's DataItem which by default is a DataRowView when you're using a default SqlDataSource. Then get the value from the column in the DataRowView, see if it's not null and see if you can find it in the DropDownList. The following should work:
Code:
Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles DetailsView1.DataBound
Select Case DetailsView1.CurrentMode
Case DetailsViewMode.Edit
Dim myDataRowView As DataRowView = DetailsView1.DataItem
If myDataRowView("Description") IsNot DBNull.Value Then
Dim myDropDownList As DropDownList = _
CType(DetailsView1.FindControl("DropDownList1"), DropDownList)
If myDropDownList.Items.FindByValue(myDataRowView("Description")) _
IsNot Nothing Then
myDropDownList.Items.FindByValue(myDataRowView("Description")).Selected = True
End If
End If
End Select
End Sub
There might be more efficient ways to do this though....
They say about .NET that it makes difficult things easy, and easy things difficult. I don't think that has changed much for .NET 2.0.... ;)
Hope this helps,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to:
Here To Stay by
KoRn (Track 1 from the album:
Untouchables)
What's This?