1.下载日历页面
http://scottonwriting.net/sowBlog/CodeProjectFiles/cal.zip
2.修改界面:
<%@ Control language="c#" Inherits="Dottext.Web.UI.Controls.Calendar" %>
<asp:Calendar id="entryCal" runat="server" SelectionMode="None" Width="220px"
DayNameFormat="FirstLetter"
Height="200px" BorderWidth="1px" ShowGridLines="False" CssClass="Cal">
<TodayDayStyle CssClass="CalTodayDay"></TodayDayStyle>
<SelectorStyle CssClass="CalSelector"></SelectorStyle>
<NextPrevStyle CssClass="CalNextPrev"></NextPrevStyle>
<DayHeaderStyle CssClass="CalDayHeader"></DayHeaderStyle>
<SelectedDayStyle CssClass="CalSelectedDay"></SelectedDayStyle>
<TitleStyle CssClass="CalTitle "></TitleStyle>
<WeekendDayStyle CssClass="CalWeekendDay"></WeekendDayStyle>
<OtherMonthDayStyle CssClass="CalOtherMonthDay"></OtherMonthDayStyle>
</asp:Calendar>
3.修改CS文件:
(1)域名空间改为:namespace Dottext.Web.UI.Controls
(2)控件从UserControl继承改为从BaseControl继承
(3)增加using:
using System.Threading;
using System.Globalization;
using Dottext.Framework.Configuration;
(3)加入<定制日历控件显示的星期文字>功能:
private void entryCal_PreRender(object sender, System.EventArgs e)
{
Thread t=Thread.CurrentThread;
CultureInfo oldCulture=t.CurrentCulture;
CultureInfo newci=(CultureInfo)oldCulture.Clone();
newci.DateTimeFormat.DayNames=new string[]{"日","一","二","三","四","五","六"};
newci.DateTimeFormat.FirstDayOfWeek=DayOfWeek.Sunday;
t.CurrentCulture=newci;
//注:不要忘了设置DayNameFormat="Full"。
}
(4)在InitializeComponent中加入一行:
this.entryCal.PreRender += new System.EventHandler(this.entryCal_PreRender);
(5)选择数据库的修改...(未完成)
4.修改CSS文件(一般是skins/??/style.css):
.Cal
{
border : 1px solid #999999;
width:100%;
font-family:Arial;
font-size: 12px;
margin-top:10px;
margin-bottom:10px;
height:180px;
background-color:#EEEEEE;
}
.CalTitle
{
background-color : #B6B6B6;
border-color:#ADF;
font-family:Arial;
font-size: 13px;
color : #000;
margin-left : 0px;
padding : 0px;
height:100%;
font-weight:bold;
}
.CalOtherMonthDay
{
color:#808080;
}
.CalSelector
{
}
.CalNextPrev
{
}
.CalDayHeader
{
background-color:#CCCCCC;
}
.CalSelectedDay
{
}
.CalWeekendDay
{
}
.CalTodayDay
{
background-color:#CCCCCC;
}
5.页面放到skins/??/controls下,CS文件放在UI/controls下
6.如果想更好地使用CSS,可以看 Daniel Cazzulino的文章“style free calendar control”
http://weblogs.asp.net/cazzu/archive/2004/02/02/66130.aspx
7.参考文件:
Giving .Text a Calendar View
http://scottonwriting.net/sowblog/posts/708.aspx
Calendar Control
http://scottwater.com/blog/archive/2004/02/13/CalendarControl.aspx
DUDU的BLOG:
如何修改日历的CSS
http://www.cnblogs.com/dudu/archive/2004/02/19/1400.aspx
如何定制日历控件显示的星期文字
http://www.cnblogs.com/dudu/archive/2004/02/18/1360.aspx