Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Problem with calendar control in DetailsVIew using ASP.NET

Reply
Thread Tools

Problem with calendar control in DetailsVIew using ASP.NET

 
 
aj
Guest
Posts: n/a
 
      05-14-2010
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I access a calendar control inside a detailsview control? Tamer Ibrahim ASP .Net Datagrid Control 3 01-30-2007 11:02 PM
Problem with a Calendar in DetailsView jerome.decouenne@gmail.com ASP .Net Web Controls 0 05-22-2006 12:27 PM
DetailsView using Calendar Control in EditItemTemplate K B ASP .Net 0 04-20-2006 03:22 AM
DetailsView - Changing to Insert Mode (Not By Using the Insert Button In the DetailsView Control) Feege ASP .Net Web Controls 0 12-20-2005 12:28 AM
Calendar Control - Programatically set the calendar to a date range Shevek ASP .Net 3 06-23-2004 01:41 PM



Advertisments