Bound control amd null values

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.....

<asp:DropDownList 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>
</asp:DropDownList>

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top