PC Review


Reply
Thread Tools Rate Thread

Calendar Control - Programatically set the calendar to a date range

 
 
Shevek
Guest
Posts: n/a
 
      23rd Jun 2004
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
 
Reply With Quote
 
 
 
 
avnrao
Guest
Posts: n/a
 
      23rd Jun 2004
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.DayRenderEventArgs e )
{
if (e.Day.Date >= Page.StartDate && e.Day.Date <= Page.EndDate)
{
e.Cell.BackColor = System.Drawing.Color.LightGray;
}
}

hth,
Av.

"Shevek" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
Shevek
Guest
Posts: n/a
 
      23rd Jun 2004
On Wed, 23 Jun 2004 18:01:57 +0530, "avnrao" <(E-Mail Removed)>
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.DayRenderEventArgs 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 If
>Av.
>
>"Shevek" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>> 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
 
Reply With Quote
 
Shevek
Guest
Posts: n/a
 
      23rd Jun 2004
On Wed, 23 Jun 2004 13:59:38 +0100, Shevek
<(E-Mail Removed)> wrote:

>On Wed, 23 Jun 2004 18:01:57 +0530, "avnrao" <(E-Mail Removed)>
>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.DayRenderEventArgs 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" <(E-Mail Removed)> wrote in message
>>news:(E-Mail Removed)...
>>> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Calendar's for date range =?Utf-8?B?SmFjaQ==?= Microsoft Access Queries 1 13th Sep 2007 04:32 PM
Searching The Calendar By Date Range =?Utf-8?B?bWJlYWNo?= Microsoft Outlook Calendar 2 26th Oct 2006 04:34 PM
Calendar Date Range Yoav Microsoft Outlook Calendar 0 24th Mar 2006 11:33 AM
Calendar Control Range bonehead Microsoft Access Form Coding 0 9th Jan 2004 06:05 PM
Calendar Date Range Leighton Microsoft Outlook Calendar 0 8th Aug 2003 04:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:59 PM.