Calendar Control dont display Other Month

Discussion in 'ASP .Net' started by bb, Jun 17, 2004.

  1. bb

    bb Guest

    any way to prevent displaying the previous and next months in the
    calendar control?

    i have tried just blanking the text out in the dayrender IsOtherMonth
    and also dynamically changing the FirstDayOfWeek to day 1 of the month.
    but neither works properly. (the boxes still appear just with no text in
    them)

    i want the calendar to start on day 1 of month and end on Day 31 (with
    acceptable trailing blanks between day 31 and the end of that week.


    --
    ------------------------
    Think your smart?
    Prove your programming power @ the OSI Geek Challenges
    http://www.osix.net
    ------------------------
     
    bb, Jun 17, 2004
    #1
    1. Advertising

  2. Here's one way to do that. You can read the explanation in the inline
    comments.

    Private Sub Page_Load _
    (ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles MyBase.Load
    ' By Ken Cox - June 17/2004
    ' Shows the first day of the month as the first day of
    ' the week in the calendar

    ' Hide the next/previous months
    Calendar1.ShowNextPrevMonth = False
    ' Create a CultureInfo object for Canada
    ' (Canadian date format is "dd/MM/yyyy")
    Dim MyCultureInfo As System.Globalization.CultureInfo
    MyCultureInfo = New System.Globalization.CultureInfo("en-CA")
    ' Build a date string using the first day of the month,
    ' the current month and current year
    Dim dtString As String = "01/" & _
    Now.Month.ToString & "/" & Now.Year.ToString
    ' Convert the string into a datetime according to the culture
    Dim dt As DateTime = DateTime.Parse(dtString, MyCultureInfo)
    ' Set the calendar's first day of week to the
    ' First day of the week of this month
    Calendar1.FirstDayOfWeek = dt.DayOfWeek
    ' Set the calendar to show this month and day
    Calendar1.TodaysDate = Now
    Calendar1.VisibleDate = Now
    End Sub

    Private Sub Calendar1_DayRender _
    (ByVal sender As Object, _
    ByVal e As System.Web.UI. _
    WebControls.DayRenderEventArgs) _
    Handles Calendar1.DayRender
    If e.Day.IsOtherMonth Then
    e.Cell.Text = " "
    End If
    End Sub

    Does this help?

    Ken
    Microsoft MVP [ASP.NET]


    "bb" <> wrote in message
    news:...
    > any way to prevent displaying the previous and next months in the calendar
    > control?
    >
    > i have tried just blanking the text out in the dayrender IsOtherMonth and
    > also dynamically changing the FirstDayOfWeek to day 1 of the month. but
    > neither works properly. (the boxes still appear just with no text in them)
    >
    > i want the calendar to start on day 1 of month and end on Day 31 (with
    > acceptable trailing blanks between day 31 and the end of that week.
    >
    >
    > --
    > ------------------------
    > Think your smart?
    > Prove your programming power @ the OSI Geek Challenges
    > http://www.osix.net
    > ------------------------
     
    Ken Cox [Microsoft MVP], Jun 17, 2004
    #2
    1. Advertising

  3. bb

    bb Guest

    Ken Cox [Microsoft MVP] wrote:

    > Here's one way to do that. You can read the explanation in the inline
    > comments.
    >
    > Private Sub Page_Load _
    > (ByVal sender As System.Object, _
    > ByVal e As System.EventArgs) _
    > Handles MyBase.Load
    > ' By Ken Cox - June 17/2004
    > ' Shows the first day of the month as the first day of
    > ' the week in the calendar
    >
    > ' Hide the next/previous months
    > Calendar1.ShowNextPrevMonth = False
    > ' Create a CultureInfo object for Canada
    > ' (Canadian date format is "dd/MM/yyyy")
    > Dim MyCultureInfo As System.Globalization.CultureInfo
    > MyCultureInfo = New System.Globalization.CultureInfo("en-CA")
    > ' Build a date string using the first day of the month,
    > ' the current month and current year
    > Dim dtString As String = "01/" & _
    > Now.Month.ToString & "/" & Now.Year.ToString
    > ' Convert the string into a datetime according to the culture
    > Dim dt As DateTime = DateTime.Parse(dtString, MyCultureInfo)
    > ' Set the calendar's first day of week to the
    > ' First day of the week of this month
    > Calendar1.FirstDayOfWeek = dt.DayOfWeek
    > ' Set the calendar to show this month and day
    > Calendar1.TodaysDate = Now
    > Calendar1.VisibleDate = Now
    > End Sub
    >
    > Private Sub Calendar1_DayRender _
    > (ByVal sender As Object, _
    > ByVal e As System.Web.UI. _
    > WebControls.DayRenderEventArgs) _
    > Handles Calendar1.DayRender
    > If e.Day.IsOtherMonth Then
    > e.Cell.Text = "&nbsp;"
    > End If
    > End Sub
    >
    > Does this help?
    >
    > Ken
    > Microsoft MVP [ASP.NET]
    >
    >
    > "bb" <> wrote in message
    > news:...
    >
    >> any way to prevent displaying the previous and next months in the
    >> calendar control?
    >>
    >> i have tried just blanking the text out in the dayrender IsOtherMonth
    >> and also dynamically changing the FirstDayOfWeek to day 1 of the
    >> month. but neither works properly. (the boxes still appear just with
    >> no text in them)
    >>
    >> i want the calendar to start on day 1 of month and end on Day 31 (with
    >> acceptable trailing blanks between day 31 and the end of that week.
    >>
    >>
    >> --
    >> ------------------------
    >> Think your smart?
    >> Prove your programming power @ the OSI Geek Challenges
    >> http://www.osix.net
    >> ------------------------

    >
    >

    Thanks .. i have tried this,

    but it doesnt seem to display correctly for me, i implement your code,
    and now i get blank row first line in the calendar and the first entry
    on the second line is correctly the first of the month.

    anyway to get rid of that blank row??

    i have tried setting the othermonth to both nbsp and clearing the cell.
    the problem is i dont want a blank cell! i want the first day of the
    month to appear as the very first 1,1 cell in the calendar

    thanks in advance

    db

    --
    ------------------------
    Think your smart?
    Prove your programming power @ the OSI Geek Challenges
    http://www.osix.net
    ------------------------
     
    bb, Jul 6, 2004
    #3
    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. msnews.microsoft.com
    Replies:
    2
    Views:
    488
    Steven Cheng[MSFT]
    Apr 22, 2004
  2. Mufasa
    Replies:
    0
    Views:
    406
    Mufasa
    Sep 5, 2008
  3. msnews.microsoft.com

    Calendar Control: Changing the Month Display and Navigation Links

    msnews.microsoft.com, Apr 19, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    188
    Steven Cheng[MSFT]
    Apr 20, 2004
  4. M. D'Costa

    Web calendar control to display a single month only

    M. D'Costa, Sep 23, 2004, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    129
    Ken Cox [Microsoft MVP]
    Sep 23, 2004
  5. Garg
    Replies:
    0
    Views:
    183
Loading...

Share This Page