Calendar Control - Programatically set the calendar to a date range

Discussion in 'ASP .Net' started by Shevek, Jun 23, 2004.

  1. Shevek

    Shevek Guest

    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, Jun 23, 2004
    #1
    1. Advertising

  2. Shevek

    avnrao Guest

    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" <> wrote in message
    news:...
    > 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
    avnrao, Jun 23, 2004
    #2
    1. Advertising

  3. Shevek

    Shevek Guest

    On Wed, 23 Jun 2004 18:01:57 +0530, "avnrao" <>
    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" <> wrote in message
    >news:...
    >> 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
    Shevek, Jun 23, 2004
    #3
  4. Shevek

    Shevek Guest

    On Wed, 23 Jun 2004 13:59:38 +0100, Shevek
    <> wrote:

    >On Wed, 23 Jun 2004 18:01:57 +0530, "avnrao" <>
    >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" <> wrote in message
    >>news:...
    >>> 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
    Shevek, Jun 23, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,244
    Michael Borgwardt
    May 30, 2004
  2. nicknack

    limit date range with calendar

    nicknack, Mar 11, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    901
    nicknack
    Mar 12, 2007
  3. Phil Streiff

    Calendar control - date range

    Phil Streiff, Oct 6, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    278
    Phil Streiff
    Oct 6, 2003
  4. Shevek
    Replies:
    0
    Views:
    380
    Shevek
    Jun 23, 2004
  5. Replies:
    2
    Views:
    292
Loading...

Share This Page