Share via


MonthChangedEventArgs.NewDate プロパティ

定義

Calendar コントロールに現在表示されている月を決定する日付を取得します。

public:
 property DateTime NewDate { DateTime get(); };
public DateTime NewDate { get; }
member this.NewDate : DateTime
Public ReadOnly Property NewDate As DateTime

プロパティ値

DateTime

Calendar によって現在表示されている月を決定する日付。

次のコード例は、プロパティの NewDate 月と PreviousDate プロパティを比較して、コントロールが 1 か月前または 1 か月後のどちらに移動したかを Calendar 判断する方法を示しています。

<%@ Page Language="C#" AutoEventWireup="True" %>

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

<head runat="server">
    <title> Calendar VisibleMonthChanged Example </title>
<script runat="server">

      void MonthChange(Object sender, MonthChangedEventArgs e) 
      {

         if (e.NewDate.Month > e.PreviousDate.Month)
         { 
            Message.Text = "You moved forward one month.";
         }
         else
         {
            Message.Text = "You moved backwards one month.";
         }

      }
         
   </script>
 
</head>
 
<body>
 
   <form id="form1" runat="server">

      <h3> Calendar VisibleMonthChanged Example </h3>
       
      Select a different month on the calendar. 
      <br /><br />
 
      <asp:Calendar id="Calendar1" runat="server"
           OnVisibleMonthChanged="MonthChange">

         <WeekendDayStyle BackColor="gray">
         </WeekendDayStyle>

      </asp:Calendar>

      <hr /> 

      <table border="1">

         <tr style="background-color:Silver">

            <th>

               Month navigation direction

            </th>
         </tr>

         <tr>

            <td>
           
               <asp:Label id="Message" 
                    Text="Starting month." 
                    runat="server"/>

            </td>

         </tr>

      </table>
                   
   </form>
         
</body>

</html>
<%@ Page Language="VB" AutoEventWireup="True" %>

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

<head runat="server">
    <title> Calendar VisibleMonthChanged Example </title>
<script runat="server">

      Sub MonthChange(sender As Object, e As MonthChangedEventArgs) 

         If e.NewDate.Month > e.PreviousDate.Month Then
         
            Message.Text = "You moved forward one month."
         
         Else
         
            Message.Text = "You moved backwards one month."
       
         End If

      End Sub
         
   </script>
 
</head>
 
<body>
 
   <form id="form1" runat="server">

      <h3> Calendar VisibleMonthChanged Example </h3>
       
      Select a different month on the calendar. 
      <br /><br />
 
      <asp:Calendar id="Calendar1" runat="server"
           OnVisibleMonthChanged="MonthChange">

         <WeekendDayStyle BackColor="gray">
         </WeekendDayStyle>

      </asp:Calendar>

      <hr /> 

      <table border="1">

         <tr style="background-color:Silver">

            <th>

               Month navigation direction

            </th>
         </tr>

         <tr>

            <td>
           
               <asp:Label id="Message" 
                    Text="Starting Month." 
                    runat="server"/>

            </td>

         </tr>

      </table>
                   
   </form>
         
</body>

</html>

注釈

コントロールによって Calendar 現在表示されている月を取得し、現在表示されている月と別の月を比較するには、このプロパティを使用します。 たとえば、このプロパティを使用して、特定の日付までの月数を計算できます。

通常、この日付は現在表示されている月の最初の日付です。ただし、プログラムを使用して月内の任意の日付に変更できます。

このプロパティは VisibleDate 、ユーザーがコントロールのナビゲーション コントロールをクリックしたときに月の変更をオーバーライドするために、プログラムでこのプロパティに Calendar 割り当てることができます。

適用対象

こちらもご覧ください