C
Chris
I have some drop downs in a formview. I am binding them to a datasource with
the bind syntax e.g. SelectedValue='<%# Bind("DirectorID") %>' . This works
fine when there is a value to be bound to, but when the underlying data is
null I get an error saying the value is not in the list. I have used the
code below with the eval syntax, but I can't get it to work with bind. Can
anyone point me in the right direction or better still give an alternative
as this seems a bit fiddly. Ideally I would like to create a control which
adds a "Please select" item only if the underlying value is null. I haven't
got clue where to start with that.....
<aspropDownList ID="drpTeamDirector" AppendDataBoundItems="True"
SelectedValue='<%# nulltest(eval("DirectorID")) %>' runat="server"
DataSourceID="odsEmployees" DataTextField="Name"
DataValueField="EmployeeID">
<asp:ListItem Selected="True" Value="0">Please Select</asp:ListItem>
</aspropDownList>
Public Function nulltest(ByVal drpnull As Object) As Integer
If drpnull Is DBNull.Value Then
Return 0
Else
Return CInt(drpnull)
End If
End Function
the bind syntax e.g. SelectedValue='<%# Bind("DirectorID") %>' . This works
fine when there is a value to be bound to, but when the underlying data is
null I get an error saying the value is not in the list. I have used the
code below with the eval syntax, but I can't get it to work with bind. Can
anyone point me in the right direction or better still give an alternative
as this seems a bit fiddly. Ideally I would like to create a control which
adds a "Please select" item only if the underlying value is null. I haven't
got clue where to start with that.....
<aspropDownList ID="drpTeamDirector" AppendDataBoundItems="True"
SelectedValue='<%# nulltest(eval("DirectorID")) %>' runat="server"
DataSourceID="odsEmployees" DataTextField="Name"
DataValueField="EmployeeID">
<asp:ListItem Selected="True" Value="0">Please Select</asp:ListItem>
</aspropDownList>
Public Function nulltest(ByVal drpnull As Object) As Integer
If drpnull Is DBNull.Value Then
Return 0
Else
Return CInt(drpnull)
End If
End Function