Calendar Control dont display Other Month

B

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.


--
 
K

Ken Cox [Microsoft MVP]

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]
 
B

bb

Ken said:
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]


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

--
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top