How set Calendar defaultdate in FormView

C

Cirene

I have a formview control.

When the user goes into insert mode I want to set the Calendar to today's
date.

How can I accomplish this? I know it's probably only 1 or 2 lines of code.

I tried this, but it doesn't work..
Protected Sub FormView1_ModeChanging(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.FormViewModeEventArgs) Handles
FormView1.ModeChanging
If e.NewMode = FormViewMode.Insert Then
Dim cal As Calendar =
CType(Me.FormView1.Row.FindControl("calDeadline"), Calendar)
cal.SelectedDate = Now.Date
End If
End Sub

Thanks!
 
M

Michael Nemtsev, MVP

Hello Cirene,

What exactly doesn't work? You can't find the control, or the date not changes


---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


C> ModeChanging(ByVal sender As Object, ByVal e As
C> System.Web.UI.WebControls.FormViewModeEventArgs) Handles
C> FormView1.ModeChanging
C> If e.NewMode = FormViewMode.Insert Then
C> Dim cal As Calendar =
C> CType(Me.FormView1.Row.FindControl("calDeadline"), Calendar)
C> cal.SelectedDate = Now.Date
 
C

Cirene

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Cirene said:
After I set it it is still Nothing.

Hello Cirene,

What exactly doesn't work? You can't find the control, or the date not
changes


---
WBR, Michael Nemtsev [.NET/C# MVP] :: blog:
http://spaces.live.com/laflour
"The greatest danger for most of us is not that our aim is too high and
we miss it, but that it is too low and we reach it" (c) Michelangelo

C> ModeChanging(ByVal sender As Object, ByVal e As
C> System.Web.UI.WebControls.FormViewModeEventArgs) Handles
C> FormView1.ModeChanging
C> If e.NewMode = FormViewMode.Insert Then
C> Dim cal As Calendar =
C> CType(Me.FormView1.Row.FindControl("calDeadline"), Calendar)
C> cal.SelectedDate = Now.Date
 
M

Michael Nemtsev, [MVP]

Hello Cirene,

Well... it means that you can't find the real Callendar control to set the
date

View the page source to check that you are looking for the correct control
name

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


C> Object reference not set to an instance of an object.
C> Description: An unhandled exception occurred during the execution of
C> the
C> current web request. Please review the stack trace for more
C> information
C> about the error and where it originated in the code.
C> Exception Details: System.NullReferenceException: Object reference
C> not set to an instance of an object.
C>
C> C>
After I set it it is still Nothing.

Hello Cirene,

What exactly doesn't work? You can't find the control, or the date
not changes

---
WBR, Michael Nemtsev [.NET/C# MVP] :: blog:
http://spaces.live.com/laflour
"The greatest danger for most of us is not that our aim is too high
and
we miss it, but that it is too low and we reach it" (c) Michelangelo
C> ModeChanging(ByVal sender As Object, ByVal e As
C> System.Web.UI.WebControls.FormViewModeEventArgs) Handles
C> FormView1.ModeChanging
C> If e.NewMode = FormViewMode.Insert Then
C> Dim cal As Calendar =
C> CType(Me.FormView1.Row.FindControl("calDeadline"), Calendar)
C> cal.SelectedDate = Now.Dat
 

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

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top