Calendar Web Control

C

Chris Beres

Greetings,

By default the calendar control displays not only the current month, but
also the days from the previous and the next month (6 weeks total). Is there
a way to prevent days from other months from showing up on the calendar?
Example: If the user selects January 2007, I don't want days displayed from
December and February.

I hope that makes sense.

Thanks in advance for your help,

Chris

Here's what I got from the MSDN help:

The Calendar control displays the dates for one month at a time, with a
total of six weeks appearing at once. The control supports several types of
dates, which are described in the following table.
 
T

Tony Girgenti

Hello Chris.

It took me some time to figure this out.

It's the OtherMonthDayStyle properties.

Good luck.
Tony
 
K

Ken Cox [Microsoft MVP]

Hi Chris,

You can use the DayRender to check if the day is from another month
(IsOtherMonth ) and if so, substitute a space character.

Check out the code below and let us know if this helps?

Ken
Microsoft MVP [ASP.NET]


<%@ page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
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

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:calendar id="Calendar1" runat="server"></asp:calendar>
</div>
</form>
</body>
</html>
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top