?
Solved

how to set the selecteddate property of .NET asp:Calendar Control  when the bound item is null?

Posted on 2009-04-29
1
Medium Priority
?
487 Views
Last Modified: 2012-06-27
I have a calendar control bound  in a gridview, on add of a new item, I get the following error because the enrol_date is null:
Object cannot be cast from DBNull to other types.

If enrol_date is null I need to set cal1's  date to a different control's date eg: <asp:Calendar id="cal2" /> (and this calendar control is in the .aspx page not inside the gridview though).

Can this be done and if so how ?
<asp:Calendar ID="cal1" runat="server"   SelectedDate='<%#  Convert.ToDateTime(DataBinder.Eval(Container.DataItem, "ENROL_DATE")) %>'>
 
    </asp:Calendar>

Open in new window

0
Comment
Question by:tech_question
1 Comment
 
LVL 12

Accepted Solution

by:
williamcampbell earned 2000 total points
ID: 24264889
Check for NULL and use Cal2's value...

Some code below not pretty
SelectedDate='<%#  Convert.ToDateTime( (DataBinder.Eval(Container.DataItem, "ENROL_DATE") == DBNull ? ((Calender)FindControl(cal2)).value : DataBinder.Eval(Container.DataItem, "ENROL_DATE")) ) %>

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month16 days, 23 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question