Calendar problem!

L

Loading name...

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?
 
K

Ken Cox [Microsoft MVP]

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]
 

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

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top