473,396 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Calendar problem!

Hey

asp.net 2.0

I have a FormView on my webpage. This FormView's datasource is a
SqlDataSource object.

This SqlDataSource returns 1 datetime field. So I've added a Calendar
control to the FormView, and made this Calender control's SelectedDate:
SelectedDate='<%# Bind('helloDate') %>'

But during runtime my webpage crashes. The reason for the crash is the
datetime value I set to SelectedDate.

This is the exception I get when the webpage crash:
"Specified cast is not valid"

The datetime field had the value NULL (meaning the datetime value is not
set). Having the datetime not set means that the user hasn't decided a date
yet. so he must be able to choose a date at a later time

What should I do to fix this?
Aug 29 '06 #1
1 3610
Hello ? (a real name is more polite),

You probably need to protect yourself from a DBNull by using a little helper
function:
Function FixDBNull(ByVal inVal As Object) As DateTime
If inVal Is DBNull.Value Then
Return DateTime.Now
Else
Return inVal
End If
End Function

<asp:calendar id="calendar1" runat="server"
selecteddaystyle-backcolor="red"
selecteddate='<%#FixDBNull(eval("helloDate")) %>'
visibledate='<%# FixDBNull( eval("helloDate")) %>'
selectorstyle-backcolor="Aqua">
</asp:calendar>

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
"Loading name..." <it_consultant1@NO_SPAM.hotmail.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Hey

asp.net 2.0

I have a FormView on my webpage. This FormView's datasource is a
SqlDataSource object.

This SqlDataSource returns 1 datetime field. So I've added a Calendar
control to the FormView, and made this Calender control's SelectedDate:
SelectedDate='<%# Bind('helloDate') %>'

But during runtime my webpage crashes. The reason for the crash is the
datetime value I set to SelectedDate.

This is the exception I get when the webpage crash:
"Specified cast is not valid"

The datetime field had the value NULL (meaning the datetime value is not
set). Having the datetime not set means that the user hasn't decided a
date yet. so he must be able to choose a date at a later time

What should I do to fix this?

Aug 29 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: DFS | last post by:
If you're listening, I want the middle of the calendar (showing 1 month) to open below the cursor position. It currently opens just to the right and below the cursor position. I hunted through...
5
by: Miguel Dias Moura | last post by:
Hello, i am trying to create a .css file with several styles and apply them to the calendar control so i can change the look of: 1. Text Type and Format (Bold, Underline, etc) 2. Background...
0
by: maxrawson | last post by:
First, let me start by saying my asp.net experience is still in it's infancy so please bare with me as I try to explain my situation. I have created a single page that with the use of many...
2
by: Caesar Augustus | last post by:
First, let me start by saying my asp.net experience is still in it's infancy so please bare with me as I try to explain my situation. I have created a single page that with the use of many...
3
by: =?Utf-8?B?UGFycm90?= | last post by:
I applied the following Ajax code in my web page which has a calendar control to keep my page from completely reloading everytime something was changed. <atlas:ScriptManager ID="ScriptManager1"...
24
by: =?Utf-8?B?Tkg=?= | last post by:
I have a basic calendar and a SelectionChanged event (asp.net 2.0). How can I handle it when a user chooses the same date again, in this case the SelectionChanged event is not fired because,...
3
by: thorpk | last post by:
I posted this problem earlier in the month and some one decided it was better to change the subject and ask a completely different question. I am therefore reposting. I am hoping some one can...
0
by: mathewgk80 | last post by:
HI all, I am having popup calendar Javascript code. But i dont know how it is connecting to asp.net code.. I am using asp.net,c#.net and also using 3tier architecture with master page.... I...
4
by: gubbachchi | last post by:
Hi all, Please anybody help me solve this problem. I am stuck up with this from past 2 weeks. I am developing an application where, when the user selects date from javascript datepicker and enters...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.