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

    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

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

    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
     
    aj, May 14, 2010
    #1
    1. Advertisements

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.
Similar Threads
  1. Shevek
    Replies:
    3
    Views:
    6,568
    Shevek
    Jun 23, 2004
  2. Anders K. Jacobsen [DK]

    Problem with asp.net calendar control

    Anders K. Jacobsen [DK], Mar 12, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    461
    Anders K. Jacobsen [DK]
    Mar 12, 2005
  3. K B
    Replies:
    0
    Views:
    3,808
  4. Tamer Ibrahim

    How can I access a calendar control inside a detailsview control?

    Tamer Ibrahim, Jan 29, 2007, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    1,124
    Alvin Bruney [MVP]
    Jan 30, 2007
  5. Shevek
    Replies:
    0
    Views:
    657
    Shevek
    Jun 23, 2004
  6. Shailesh

    Problem with Calendar Control in asp.net

    Shailesh, Sep 6, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    219
    Scott M.
    Sep 6, 2004
  7. Feege
    Replies:
    0
    Views:
    802
    Feege
    Dec 20, 2005
  8. Problem with a Calendar in DetailsView

    , May 22, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    444
Loading...