Private Sub calDate_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles calDate.DayRender Dim i As Integer Dim p_stuHoliday As DateColorData() Try p_stuHoliday = CType(Page.Session("RmPrintInfo") If (e.Day.Date.DayOfWeek = DayOfWeek.Saturday) And (Not e.Day.IsOtherMonth) Then e.Cell.ForeColor = System.Drawing.Color.Blue ElseIf (e.Day.Date.DayOfWeek = DayOfWeek.Sunday) And (Not e.Day.IsOtherMonth) Then e.Cell.ForeColor = System.Drawing.Color.Red End If If Not IsNothing(p_stuHoliday) Then For i = 0 To p_stuHoliday.Length - 1 If Not e.Day.IsOtherMonth Then If e.Day.Date.Date = p_stuHoliday(i).holiday_date Then e.Cell.ForeColor = System.Drawing.Color.FromArgb(p_stuHoliday(i).color_red, p_stuHoliday(i).color_green, p_stuHoliday(i).color_blue) e.Cell.Text="XXXXXXXXXXXXXXXXX" End If End If Next End If Catch ex As Exception Throw ex Finally End Try End Sub
Sorry,上面的代码有点错误,更改如下: Private Sub calDate_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles calDate.DayRender Dim i As Integer Dim p_stuHoliday As DateColorData() Dim kk As New System.Web.UI.WebControls.Label Try p_stuHoliday = CType(Page.Session("RmPrintInfo") If (e.Day.Date.DayOfWeek = DayOfWeek.Saturday) And (Not e.Day.IsOtherMonth) Then e.Cell.ForeColor = System.Drawing.Color.Blue ElseIf (e.Day.Date.DayOfWeek = DayOfWeek.Sunday) And (Not e.Day.IsOtherMonth) Then e.Cell.ForeColor = System.Drawing.Color.Red End If If Not IsNothing(p_stuHoliday) Then For i = 0 To p_stuHoliday.Length - 1 If Not e.Day.IsOtherMonth Then If e.Day.Date.Date = p_stuHoliday(i).holiday_date Then e.Cell.ForeColor = System.Drawing.Color.FromArgb(p_stuHoliday(i).color_red, p_stuHoliday(i).color_green, p_stuHoliday(i).color_blue) kk.Text = "<br>外出" e.Cell.Controls.Add(kk) End If End If Next End If Catch ex As Exception Throw ex Finally End Try End Sub
Calendar控件中,在日历显示出添加的内容 主要用Calendar的事件:Calendar1_DayRender 当Calendar加载的时候会逐个日期(日期单元格)进行加载给你个简单的例子 private void Calendar1_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e) { // Change the background color of the days in the month to yellow. if (!e.Day.IsOtherMonth && !e.Day.IsWeekend) e.Cell.BackColor=System.Drawing.Color.Yellow;// Add custom text to cell in the Calendar control. if (e.Day.Date.Day == 18) e.Cell.Controls.Add(new LiteralControl("<br>Holiday")); }点击其中一个单元格,就会触发 Calendar1_SelectionChanged private void Calendar1_SelectionChanged(object sender, System.EventArgs e) { //Calendar选择的日期 DateTime dateCalendar ; dateCalendar = this.Calendar1.SelectedDate; //根据选择日期,进行查询数据库处理 。。 //执行相应操作 添加,修改,删除日期单元格的内容 }
<head>
<script language="C#" runat="server"> String [][] holidays; void Page_Load(Object Sender, EventArgs e) { holidays = new String[13][]; for (int n=0; n<13 ;n++)
holidays[n] = new String[32]; holidays[1][1] = "元旦";
holidays[1][26] = "澳大利亚国庆节";
holidays[2][2] = "土拨鼠日";
holidays[2][14] = "情人节";
holidays[3][17] = "圣帕特里克节";
holidays[4][1] = "愚人节";
holidays[5][1] = "国际劳动节";
holidays[6][15] = "我的生日";
holidays[7][15] = "我的纪念日";
holidays[8][15] = "我母亲的生日";
holidays[9][24] = "秋分";
holidays[12][26] = "节礼日";
} void Calendar1_DayRender(object sender, DayRenderEventArgs e) { CalendarDay d = ((DayRenderEventArgs)e).Day;
TableCell c = ((DayRenderEventArgs)e).Cell; if (d.IsOtherMonth) {
c.Controls.Clear();
}
else {
try {
string Hol = holidays[d.Date.Month][d.Date.Day]; if (Hol != string.Empty)
c.Controls.Add(new LiteralControl("<br>" + Hol));
}
catch (Exception exc) {
Response.Write (exc.ToString());
}
}
} void Date_Selected(object s, EventArgs e) {
Label1.Text = "选定日期为:" + Calendar1.SelectedDate.ToShortDateString();
} </script></head><body> <h3><font face="宋体">向日历添加自定义内容</font></h3>
<p><p> <form runat=server> <asp:Calendar id=Calendar1 runat="server"
ondayrender="Calendar1_DayRender"
onselectionchanged="Date_Selected"
ShowGridLines="true"
Font-Name="Verdana;Arial"
Font-Size="9px"
Width="500px"
VisibleDate="01/01/2000"
TitleStyle-BackColor="Gainsboro"
TitleStyle-Font-Size="12px"
TitleStyle-Font-Bold="true"
DayStyle-VerticalAlign="Top"
DayStyle-Height="50px"
DayStyle-Width="14%"
SelectedDate="1/1/0001"
SelectedDayStyle-BackColor="Navy"
/> <p>
<asp:Label id=Label1 runat="server" />
</form></body>
</html>
看过sina 和yahoo的日历管理嘛?
我做的根他们的差不多
Dim i As Integer
Dim p_stuHoliday As DateColorData() Try
p_stuHoliday = CType(Page.Session("RmPrintInfo")
If (e.Day.Date.DayOfWeek = DayOfWeek.Saturday) And (Not e.Day.IsOtherMonth) Then
e.Cell.ForeColor = System.Drawing.Color.Blue
ElseIf (e.Day.Date.DayOfWeek = DayOfWeek.Sunday) And (Not e.Day.IsOtherMonth) Then
e.Cell.ForeColor = System.Drawing.Color.Red
End If
If Not IsNothing(p_stuHoliday) Then
For i = 0 To p_stuHoliday.Length - 1
If Not e.Day.IsOtherMonth Then
If e.Day.Date.Date = p_stuHoliday(i).holiday_date Then
e.Cell.ForeColor = System.Drawing.Color.FromArgb(p_stuHoliday(i).color_red, p_stuHoliday(i).color_green, p_stuHoliday(i).color_blue)
e.Cell.Text="XXXXXXXXXXXXXXXXX"
End If
End If
Next
End If
Catch ex As Exception
Throw ex
Finally
End Try
End Sub
Private Sub calDate_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles calDate.DayRender
Dim i As Integer
Dim p_stuHoliday As DateColorData()
Dim kk As New System.Web.UI.WebControls.Label Try
p_stuHoliday = CType(Page.Session("RmPrintInfo")
If (e.Day.Date.DayOfWeek = DayOfWeek.Saturday) And (Not e.Day.IsOtherMonth) Then
e.Cell.ForeColor = System.Drawing.Color.Blue
ElseIf (e.Day.Date.DayOfWeek = DayOfWeek.Sunday) And (Not e.Day.IsOtherMonth) Then
e.Cell.ForeColor = System.Drawing.Color.Red
End If
If Not IsNothing(p_stuHoliday) Then
For i = 0 To p_stuHoliday.Length - 1
If Not e.Day.IsOtherMonth Then
If e.Day.Date.Date = p_stuHoliday(i).holiday_date Then
e.Cell.ForeColor = System.Drawing.Color.FromArgb(p_stuHoliday(i).color_red, p_stuHoliday(i).color_green, p_stuHoliday(i).color_blue)
kk.Text = "<br>外出"
e.Cell.Controls.Add(kk)
End If
End If
Next
End If
Catch ex As Exception
Throw ex
Finally
End Try
End Sub
先看看你的需求和新浪日历是否相似,我做的和它的差不多,在日历页面中可可以显示标志
我说的是功能,具体怎么做可以帮你你先看看吧
主要用Calendar的事件:Calendar1_DayRender
当Calendar加载的时候会逐个日期(日期单元格)进行加载给你个简单的例子
private void Calendar1_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
{
// Change the background color of the days in the month to yellow.
if (!e.Day.IsOtherMonth && !e.Day.IsWeekend)
e.Cell.BackColor=System.Drawing.Color.Yellow;// Add custom text to cell in the Calendar control. if (e.Day.Date.Day == 18)
e.Cell.Controls.Add(new LiteralControl("<br>Holiday"));
}点击其中一个单元格,就会触发 Calendar1_SelectionChanged
private void Calendar1_SelectionChanged(object sender, System.EventArgs e)
{
//Calendar选择的日期
DateTime dateCalendar ;
dateCalendar = this.Calendar1.SelectedDate;
//根据选择日期,进行查询数据库处理
。。
//执行相应操作
添加,修改,删除日期单元格的内容
}
这个是什么?//如果每月的日期等于18日,就在日期单元格中添加 Holiday
if (e.Day.Date.Day == 18)
e.Cell.Controls.Add(new LiteralControl("<br>Holiday"));
}这样就可以变通一下了,不用我讲得更详细了吧
你从数据库中读你的数据表,包括日期,内容for (int i =0 ; i<DataTable.Rows.Count; i++)
{
DateTime m_date = DateTime(DataTable.Rows[i][日期]);
//当e.Day.Date.Day == “你的日期”
if(e.Day.Date == m_date)
{
e.Cell.Controls.Add (new LiteralControl("你要添加的内容"));
}
}