468,720 Members | 1,873 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Calendar Control dont display Other Month

bb
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
------------------------
Nov 18 '05 #1
2 6765
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" <bb**@t.osix.net> wrote in message
news:uU**************@TK2MSFTNGP11.phx.gbl...
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
------------------------


Nov 18 '05 #2
bb
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" <bb**@t.osix.net> wrote in message
news:uU**************@TK2MSFTNGP11.phx.gbl...
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
------------------------
Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

19 posts views Thread by Stimp | last post: by
27 posts views Thread by Dino M. Buljubasic | last post: by
3 posts views Thread by Peter | last post: by
1 post views Thread by Jessica Weiner | last post: by
1 post views Thread by Oskars | last post: by
9 posts views Thread by bryonone | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.