Problem with calendar control in DetailsVIew using ASP.NET

Discussion in 'ASP .Net Web Controls' started by aj, May 14, 2010.

  1. aj

    aj Guest


    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

    <asp:DetailsView ID="Dtv2SDCUpdate" runat="server"
    DataKeyNames="company, content"
    <asp:TemplateField HeaderText="End Date">
    <asp:TextBox ID="EditenddateTextBox"
    Text='<%# Bind("end_date") %>' />
    <asp:Calendar ID="EndDateCal" runat="server"
    Chk(Bind("end_date")) %>'
    Chk(Bind("end_date")) %>'>
    <asp:Label ID="LblEndDate" runat="server" Text='<
    %# Bind("end_date") %>' />


    I have a function to check is the date field is NULL

    Public Function ChkDate(ByVal d As Object) As DateTime
    If Not TypeOf d Is DBNull Then
    Return CDate(d).ToString
    End If
    End Function
    aj, May 14, 2010
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.