在恆逸資訊最新版的精通C#與ASP.NET程式設計中有行事历的例程,用到Calendar.Render来实现你的方法,我现在暂时还查不到,记住是新版,不是黄颜色的老版。

解决方案 »

  1.   

    http://chs.gotdotnet.com/quickstart/aspplus/samples/webforms/ctrlref/webctrl/calendar/doc_cal.aspx#custom
      

  2.   

    我看到例子了!可是可能我是蔡鸟!我不知道怎么设计数据库!她是使用数组实现的,我怎么判断我要读进取的数据呢??那位大哥能指点一下~!~!~!程序各位先看看html>
    <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>
      

  3.   

    这个很容易实现,我做的比它的好
    看过sina 和yahoo的日历管理嘛?
    我做的根他们的差不多
      

  4.   

    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
      

  5.   

    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
      

  6.   

    http://calendar.sina.com.cn
    先看看你的需求和新浪日历是否相似,我做的和它的差不多,在日历页面中可可以显示标志
    我说的是功能,具体怎么做可以帮你你先看看吧
      

  7.   

    注册个新浪会员,进入Calendar,反正也是免费的
      

  8.   

    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;
    //根据选择日期,进行查询数据库处理
             。。
             //执行相应操作
             添加,修改,删除日期单元格的内容
    }
      

  9.   

    怎么没有?
    这个是什么?//如果每月的日期等于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("你要添加的内容"));
    }
    }