2013-10-22 44 views

回答

2

您將需要使用DayRender方法。

C#代碼隱藏

public void Calendar1_DayRender(object o, DayRenderEventArgs e) 
      { 


       e.Cell.BackColor = System.Drawing.Color.Empty; 
       e.Cell.ForeColor = System.Drawing.Color.DarkRed; 

       //if the days are not part of the current month 
       if (e.Day.IsOtherMonth) 
       { 
        e.Cell.Text = ""; 
       } 
      } 

然後在日曆中,您需要將

ASP

<asp:Calendar ID="Calendar1" runat="server" Height="145px" Width="77px" OnDayRender="Calendar1_DayRender"></asp:Calendar> 

您添加OnDayRender = 「Calendar1_DayRender」 日曆控制。

希望這會有所幫助!

編輯:我誤讀了。但是,如果你想只爲「Enable」當天並沒有其他的日子,那麼這將工作..

代碼隱藏

public void Calendar1_DayRender(object o, DayRenderEventArgs e) 
     { 


      e.Cell.BackColor = System.Drawing.Color.Empty; 
      e.Cell.ForeColor = System.Drawing.Color.DarkRed; 

      if (e.Day.IsToday) 
      { 
       e.Cell.BackColor = System.Drawing.Color.Blue; 
      } 
      else 
      { 
       e.Cell.Text = ""; 
      } 
     } 
+0

我想念那個。我會再看一次。 – Humpy

+0

謝謝你的迴應先生! –

+0

@JbMeris這是否解決了您的問題?這是你在找什麼? – Humpy

1

您可以使用這種伎倆來禁用日曆將來的日期控制。

protected void Calendar1_DayRender(object sender, DayRenderEventArgs e) 
{ 

    if (e.Day.Date > DateTime.Today) 
    { 

    e.Day.IsSelectable = false; 
    } 

} 
+1

嗨,它應該是「如果(e.Day.Date> DateTime.Today)」。 – netcat

+0

謝謝@Mattzz –