G
Guest
Ok, I'm lost. I'm writing a webpage in VB/Dot Net 2.0 and I'm trying to put a
dropdown list in a detailsview. The dropdownlist is supposed to display a
simple enum.
From what little I've seen so far, the place in VB code to bind a ddl is in
the detailview's databound event. Any earlier and you can't get a handle on
the ddl. The detailsview is essentially alone on it's page and is called in
either edit or insert mode only. (In the page lode, I examine a querystring
parameter and based on that, set the detailsview to either edit or insert
mode.) I have created template ddls in the column corresponding to this
variable. All existing records have valid values in this field (a smallint).
The code itself is routine:
ddlClassType = DetailsView1.FindControl("ddlClassType")
Dim names() As String = System.Enum.GetNames(GetType(ClassType))
Dim values() As Integer = System.Enum.GetValues(GetType(ClassType))
Dim i As Integer
For i = 0 To names.Length - 1
Dim item As New ListItem(names(i), values(i).ToString)
ddlClassType.Items.Add(item)
Next
This works fine for Inserts but the code never gets to this point for
updates. It crashes with the error: 'ddlClassType' has a SelectedValue which
is invalid because it does not exist in the list of items. Parameter name:
value
Any suggestions?
dropdown list in a detailsview. The dropdownlist is supposed to display a
simple enum.
From what little I've seen so far, the place in VB code to bind a ddl is in
the detailview's databound event. Any earlier and you can't get a handle on
the ddl. The detailsview is essentially alone on it's page and is called in
either edit or insert mode only. (In the page lode, I examine a querystring
parameter and based on that, set the detailsview to either edit or insert
mode.) I have created template ddls in the column corresponding to this
variable. All existing records have valid values in this field (a smallint).
The code itself is routine:
ddlClassType = DetailsView1.FindControl("ddlClassType")
Dim names() As String = System.Enum.GetNames(GetType(ClassType))
Dim values() As Integer = System.Enum.GetValues(GetType(ClassType))
Dim i As Integer
For i = 0 To names.Length - 1
Dim item As New ListItem(names(i), values(i).ToString)
ddlClassType.Items.Add(item)
Next
This works fine for Inserts but the code never gets to this point for
updates. It crashes with the error: 'ddlClassType' has a SelectedValue which
is invalid because it does not exist in the list of items. Parameter name:
value
Any suggestions?