469,575 Members | 1,640 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,575 developers. It's quick & easy.

Calendar Control - Programatically set the calendar to a date range

Hi All, Hope someone can help!

I am building an Event Calendar app based around the Calendar
WebControl which builds an SQL string based on the SelectedDates
property which is passed to Page.StartDate and Page.EndDate
properties.

This works nicely and I can select a Day, Week or Month and run my SQL
against them.

There is also a shortcuts dropdown to allow the user to select Today,
Last Month, This Month, Next Month, Next Two Weeks, Next 30 Days, Next
60 Days, Next 90 Days.

Again, these all work nicely as I set the Page.StartDate and
Page.EndDate based on the option and run the SQL then update the
Calendar.VisibleDate to Page.StartDate.

The problem is it would be nice for the Calendar object to reflect the
shortcut ranges. This is OK for Today as I can just set the
SelectedDate to the Page.StartDate. However the SelectedDates property
is read only.

Is there any way to set a range of dates to be selected based on the
Page.StartDate and Page.EndDate properties?

Many TIA

--
Shevek

The Poster Previously Known As Moldy
Nov 18 '05 #1
3 3449
you can write a handler for DayRender event and check for the date and
change color accordingly.

private void Calendar1_DayRender(object
sender,System.Web.UI.WebControls.DayRenderEventArg s e )
{
if (e.Day.Date >= Page.StartDate && e.Day.Date <= Page.EndDate)
{
e.Cell.BackColor = System.Drawing.Color.LightGray;
}
}

hth,
Av.

"Shevek" <sh****************@moldy.me.uk> wrote in message
news:uk********************************@4ax.com...
Hi All, Hope someone can help!

I am building an Event Calendar app based around the Calendar
WebControl which builds an SQL string based on the SelectedDates
property which is passed to Page.StartDate and Page.EndDate
properties.

This works nicely and I can select a Day, Week or Month and run my SQL
against them.

There is also a shortcuts dropdown to allow the user to select Today,
Last Month, This Month, Next Month, Next Two Weeks, Next 30 Days, Next
60 Days, Next 90 Days.

Again, these all work nicely as I set the Page.StartDate and
Page.EndDate based on the option and run the SQL then update the
Calendar.VisibleDate to Page.StartDate.

The problem is it would be nice for the Calendar object to reflect the
shortcut ranges. This is OK for Today as I can just set the
SelectedDate to the Page.StartDate. However the SelectedDates property
is read only.

Is there any way to set a range of dates to be selected based on the
Page.StartDate and Page.EndDate properties?

Many TIA

--
Shevek

The Poster Previously Known As Moldy

Nov 18 '05 #2
On Wed, 23 Jun 2004 18:01:57 +0530, "avnrao" <av*@newsgroups.com>
wrote:
you can write a handler for DayRender event and check for the date and
change color accordingly.

private void Calendar1_DayRender(object
sender,System.Web.UI.WebControls.DayRenderEventAr gs e )
{
if (e.Day.Date >= Page.StartDate && e.Day.Date <= Page.EndDate)
{
e.Cell.BackColor = System.Drawing.Color.LightGray;
}
}

hth,
Doesn't quite work!

I already use the DayRender event to apply styles and onmouseover to
give the dates borders and rollovers.

If I change the first line to

If (e.Day.Date.ToShortDateString >= Me.StartDate And
e.Day.Date.ToShortDateString <= Me.EndDate) or e.Day.IsSelected Then

then it seems to keep the cssclass in the viewstate and is there when
I browse back and forth through the calendar....
If e.Day.IsSelected Then
If bEvent Then
e.Cell.ApplyStyle(ForeOrange)
e.Cell.CssClass = "EventSelectedDay"
e.Cell.Attributes.Add("onmouseover",
"javascript:this.className = 'EventSelectedDayOver';")
e.Cell.Attributes.Add("onmouseout",
"javascript:this.className = 'EventSelectedDay';")
Else
e.Cell.CssClass = "SelectedDay"
e.Cell.Attributes.Add("onmouseover",
"javascript:this.className = 'SelectedDayOver';")
e.Cell.Attributes.Add("onmouseout",
"javascript:this.className = 'SelectedDay';")
End If
ElseIf e.Day.IsWeekend Then
If bEvent Then
e.Cell.ApplyStyle(ForeOrange)
e.Cell.CssClass = "EventWeekendDay"
e.Cell.Attributes.Add("onmouseover",
"javascript:this.className = 'EventWeekendDayOver';")
e.Cell.Attributes.Add("onmouseout",
"javascript:this.className = 'EventWeekendDay';")
Else
e.Cell.CssClass = "WeekendDay"
e.Cell.Attributes.Add("onmouseover",
"javascript:this.className = 'WeekendDayOver';")
e.Cell.Attributes.Add("onmouseout",
"javascript:this.className = 'WeekendDay';")
End If
ElseIf e.Day.IsOtherMonth Then
If bEvent Then
e.Cell.ApplyStyle(ForeYellow)
e.Cell.CssClass = "EventOtherMonthDay"
e.Cell.Attributes.Add("onmouseover",
"javascript:this.className = 'EventOtherMonthDayOver';")
e.Cell.Attributes.Add("onmouseout",
"javascript:this.className = 'EventOtherMonthDay';")
Else
e.Cell.CssClass = "OtherMonthDay"
e.Cell.Attributes.Add("onmouseover",
"javascript:this.className = 'OtherMonthDayOver';")
e.Cell.Attributes.Add("onmouseout",
"javascript:this.className = 'OtherMonthDay';")
End If
Else
If bEvent Then
e.Cell.ApplyStyle(ForeOrange)
e.Cell.CssClass = "EventDay"
e.Cell.Attributes.Add("onmouseover",
"javascript:this.className = 'EventDayOver';")
e.Cell.Attributes.Add("onmouseout",
"javascript:this.className = 'EventDay';")
Else
e.Cell.CssClass = "Day"
e.Cell.Attributes.Add("onmouseover",
"javascript:this.className = 'DayOver';")
e.Cell.Attributes.Add("onmouseout",
"javascript:this.className = 'Day';")
End If
End IfAv.

"Shevek" <sh****************@moldy.me.uk> wrote in message
news:uk********************************@4ax.com.. .
Hi All, Hope someone can help!

I am building an Event Calendar app based around the Calendar
WebControl which builds an SQL string based on the SelectedDates
property which is passed to Page.StartDate and Page.EndDate
properties.

This works nicely and I can select a Day, Week or Month and run my SQL
against them.

There is also a shortcuts dropdown to allow the user to select Today,
Last Month, This Month, Next Month, Next Two Weeks, Next 30 Days, Next
60 Days, Next 90 Days.

Again, these all work nicely as I set the Page.StartDate and
Page.EndDate based on the option and run the SQL then update the
Calendar.VisibleDate to Page.StartDate.

The problem is it would be nice for the Calendar object to reflect the
shortcut ranges. This is OK for Today as I can just set the
SelectedDate to the Page.StartDate. However the SelectedDates property
is read only.

Is there any way to set a range of dates to be selected based on the
Page.StartDate and Page.EndDate properties?

Many TIA

--
Shevek

The Poster Previously Known As Moldy

--
Shevek

The Poster Previously Known As Moldy
Nov 18 '05 #3
On Wed, 23 Jun 2004 13:59:38 +0100, Shevek
<sh****************@moldy.me.uk> wrote:
On Wed, 23 Jun 2004 18:01:57 +0530, "avnrao" <av*@newsgroups.com>
wrote:
you can write a handler for DayRender event and check for the date and
change color accordingly.

private void Calendar1_DayRender(object
sender,System.Web.UI.WebControls.DayRenderEventA rgs e )
{
if (e.Day.Date >= Page.StartDate && e.Day.Date <= Page.EndDate)
{
e.Cell.BackColor = System.Drawing.Color.LightGray;
}
}

hth,
Doesn't quite work!

I already use the DayRender event to apply styles and onmouseover to
give the dates borders and rollovers.

If I change the first line to

If (e.Day.Date.ToShortDateString >= Me.StartDate And
e.Day.Date.ToShortDateString <= Me.EndDate) or e.Day.IsSelected Then

then it seems to keep the cssclass in the viewstate and is there when
I browse back and forth through the calendar....


Got it! It was not working because my Page.StartDate and Page.EndDate
are both dates stored as strings...

Dim dStartDate, dEndDate As Date
If IsDate(Me.StartDate) Then dStartDate = Me.StartDate
If IsDate(Me.EndDate) Then dEndDate = Me.EndDate
If (e.Day.Date >= dStartDate And e.Day.Date <= dEndDate) Then

....has fixed it!

Cheers!


If e.Day.IsSelected Then
If bEvent Then
e.Cell.ApplyStyle(ForeOrange)
e.Cell.CssClass = "EventSelectedDay"
e.Cell.Attributes.Add("onmouseover",
"javascript:this.className = 'EventSelectedDayOver';")
e.Cell.Attributes.Add("onmouseout",
"javascript:this.className = 'EventSelectedDay';")
Else
e.Cell.CssClass = "SelectedDay"
e.Cell.Attributes.Add("onmouseover",
"javascript:this.className = 'SelectedDayOver';")
e.Cell.Attributes.Add("onmouseout",
"javascript:this.className = 'SelectedDay';")
End If
ElseIf e.Day.IsWeekend Then
If bEvent Then
e.Cell.ApplyStyle(ForeOrange)
e.Cell.CssClass = "EventWeekendDay"
e.Cell.Attributes.Add("onmouseover",
"javascript:this.className = 'EventWeekendDayOver';")
e.Cell.Attributes.Add("onmouseout",
"javascript:this.className = 'EventWeekendDay';")
Else
e.Cell.CssClass = "WeekendDay"
e.Cell.Attributes.Add("onmouseover",
"javascript:this.className = 'WeekendDayOver';")
e.Cell.Attributes.Add("onmouseout",
"javascript:this.className = 'WeekendDay';")
End If
ElseIf e.Day.IsOtherMonth Then
If bEvent Then
e.Cell.ApplyStyle(ForeYellow)
e.Cell.CssClass = "EventOtherMonthDay"
e.Cell.Attributes.Add("onmouseover",
"javascript:this.className = 'EventOtherMonthDayOver';")
e.Cell.Attributes.Add("onmouseout",
"javascript:this.className = 'EventOtherMonthDay';")
Else
e.Cell.CssClass = "OtherMonthDay"
e.Cell.Attributes.Add("onmouseover",
"javascript:this.className = 'OtherMonthDayOver';")
e.Cell.Attributes.Add("onmouseout",
"javascript:this.className = 'OtherMonthDay';")
End If
Else
If bEvent Then
e.Cell.ApplyStyle(ForeOrange)
e.Cell.CssClass = "EventDay"
e.Cell.Attributes.Add("onmouseover",
"javascript:this.className = 'EventDayOver';")
e.Cell.Attributes.Add("onmouseout",
"javascript:this.className = 'EventDay';")
Else
e.Cell.CssClass = "Day"
e.Cell.Attributes.Add("onmouseover",
"javascript:this.className = 'DayOver';")
e.Cell.Attributes.Add("onmouseout",
"javascript:this.className = 'Day';")
End If
End If
Av.

"Shevek" <sh****************@moldy.me.uk> wrote in message
news:uk********************************@4ax.com. ..
Hi All, Hope someone can help!

I am building an Event Calendar app based around the Calendar
WebControl which builds an SQL string based on the SelectedDates
property which is passed to Page.StartDate and Page.EndDate
properties.

This works nicely and I can select a Day, Week or Month and run my SQL
against them.

There is also a shortcuts dropdown to allow the user to select Today,
Last Month, This Month, Next Month, Next Two Weeks, Next 30 Days, Next
60 Days, Next 90 Days.

Again, these all work nicely as I set the Page.StartDate and
Page.EndDate based on the option and run the SQL then update the
Calendar.VisibleDate to Page.StartDate.

The problem is it would be nice for the Calendar object to reflect the
shortcut ranges. This is OK for Today as I can just set the
SelectedDate to the Page.StartDate. However the SelectedDates property
is read only.

Is there any way to set a range of dates to be selected based on the
Page.StartDate and Page.EndDate properties?

Many TIA

--
Shevek

The Poster Previously Known As Moldy

--
Shevek

The Poster Previously Known As Moldy
Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Tim Graichen | last post: by
1 post views Thread by Peter | last post: by
reply views Thread by Peer K | last post: by
2 posts views Thread by Jay | last post: by
2 posts views Thread by niju | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.