A
aj
Hi
My ASP page has a Detailsview with a calendar control and textbox. The
Textbox is binding a date field in the SQL table which has NULL values
for a few records. Therefore my script is giving me the following
error message
System.InvalidCastException: Conversion from type 'DBNull' to type
'Date' is not valid.
for those records and I have not be able to solve the issue. Could
someone please help.
..ASPX page
<aspetailsView ID="Dtv2SDCUpdate" runat="server"
DataKeyNames="company, content"
<Fields>
<asp:TemplateField HeaderText="End Date">
<EditItemTemplate>
<asp:TextBox ID="EditenddateTextBox"
runat="server"
Text='<%# Bind("end_date") %>' />
<asp:Calendar ID="EndDateCal" runat="server"
SelectedDate='<%#
Chk(Bind("end_date")) %>'
VisibleDate='<%#
Chk(Bind("end_date")) %>'>
</asp:Calendar>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="LblEndDate" runat="server" Text='<
%# Bind("end_date") %>' />
</ItemTemplate>
</asp:TemplateField>
</Fields>
</aspetailsView>
I have a function to check is the date field is NULL
..VB
Public Function ChkDate(ByVal d As Object) As DateTime
If Not TypeOf d Is DBNull Then
Return CDate(d).ToString
End If
End Function
My ASP page has a Detailsview with a calendar control and textbox. The
Textbox is binding a date field in the SQL table which has NULL values
for a few records. Therefore my script is giving me the following
error message
System.InvalidCastException: Conversion from type 'DBNull' to type
'Date' is not valid.
for those records and I have not be able to solve the issue. Could
someone please help.
..ASPX page
<aspetailsView ID="Dtv2SDCUpdate" runat="server"
DataKeyNames="company, content"
<Fields>
<asp:TemplateField HeaderText="End Date">
<EditItemTemplate>
<asp:TextBox ID="EditenddateTextBox"
runat="server"
Text='<%# Bind("end_date") %>' />
<asp:Calendar ID="EndDateCal" runat="server"
SelectedDate='<%#
Chk(Bind("end_date")) %>'
VisibleDate='<%#
Chk(Bind("end_date")) %>'>
</asp:Calendar>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="LblEndDate" runat="server" Text='<
%# Bind("end_date") %>' />
</ItemTemplate>
</asp:TemplateField>
</Fields>
</aspetailsView>
I have a function to check is the date field is NULL
..VB
Public Function ChkDate(ByVal d As Object) As DateTime
If Not TypeOf d Is DBNull Then
Return CDate(d).ToString
End If
End Function