Calendar.VisibleDate プロパティ

定義

DateTime コントロールに表示する月を指定する Calendar を取得または設定します。

public:
 property DateTime VisibleDate { DateTime get(); void set(DateTime value); };
[System.ComponentModel.Bindable(true)]
public DateTime VisibleDate { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.VisibleDate : DateTime with get, set
Public Property VisibleDate As DateTime

プロパティ値

DateTime に表示する月を指定する Calendar。 既定値は DateTime.MinValue です。この値は、 で TodaysDate指定された日付を含む月を表示します。

属性

次のコード例では、 プロパティを VisibleDate 使用して、コントロールに表示される月を決定する値をプログラムで設定する方法を 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>
    <title>Calendar Example</title>
<script language="C#" runat="server">

      void ButtonClick(Object sender, EventArgs e) 
      {
         Calendar1.VisibleDate = new DateTime(Calendar1.TodaysDate.Year, 
                                              DropList1.SelectedIndex + 1, 
                                              1);
         Label1.Text = "The VisibleDate property is " + 
                       Calendar1.VisibleDate.ToShortDateString();
      }

   </script>

</head>     
<body>

   <form id="form1" runat="server">

      <h3>Calendar Example</h3>

      <asp:Calendar id="Calendar1" runat="server"  
           SelectionMode="None" 
           ShowGridLines="True">
 
         <SelectedDayStyle BackColor="Yellow"
                           ForeColor="Red">
         </SelectedDayStyle>

      </asp:Calendar>

      <hr /><br />

      Select the month to display: <br />

      <asp:DropDownList id="DropList1" runat="server">

         <asp:ListItem>1</asp:ListItem>
         <asp:ListItem>2</asp:ListItem>
         <asp:ListItem>3</asp:ListItem>
         <asp:ListItem>4</asp:ListItem>
         <asp:ListItem>5</asp:ListItem>
         <asp:ListItem>6</asp:ListItem>
         <asp:ListItem>7</asp:ListItem>
         <asp:ListItem>8</asp:ListItem>
         <asp:ListItem>9</asp:ListItem>
         <asp:ListItem>10</asp:ListItem>
         <asp:ListItem>11</asp:ListItem>
         <asp:ListItem>12</asp:ListItem>

      </asp:DropDownList>

      <asp:Button id="Button1" 
           Text="Submit"
           OnClick="ButtonClick"
           runat="server" />

      <br /><br />

      <asp:Label id="Label1" runat="server"/>

   </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>
    <title>Calendar Example</title>
<script language="VB" runat="server">

        Sub ButtonClick(sender As Object, e As EventArgs)
            Calendar1.VisibleDate = New DateTime(Calendar1.TodaysDate.Year, DropList1.SelectedIndex + 1, 1)
            Label1.Text = "The VisibleDate property is " & Calendar1.VisibleDate.ToShortDateString()
        End Sub 'ButtonClick

   </script>

</head>     
<body>

   <form id="form1" runat="server">

      <h3>Calendar Example</h3>

      <asp:Calendar id="Calendar1" runat="server"  
           SelectionMode="None" 
           ShowGridLines="True">
 
         <SelectedDayStyle BackColor="Yellow"
                           ForeColor="Red">
         </SelectedDayStyle>

      </asp:Calendar>

      <hr /><br />

      Select the month to display: <br />

      <asp:DropDownList id="DropList1" runat="server">

         <asp:ListItem>1</asp:ListItem>
         <asp:ListItem>2</asp:ListItem>
         <asp:ListItem>3</asp:ListItem>
         <asp:ListItem>4</asp:ListItem>
         <asp:ListItem>5</asp:ListItem>
         <asp:ListItem>6</asp:ListItem>
         <asp:ListItem>7</asp:ListItem>
         <asp:ListItem>8</asp:ListItem>
         <asp:ListItem>9</asp:ListItem>
         <asp:ListItem>10</asp:ListItem>
         <asp:ListItem>11</asp:ListItem>
         <asp:ListItem>12</asp:ListItem>

      </asp:DropDownList>

      <asp:Button id="Button1" 
           Text="Submit"
           OnClick="ButtonClick"
           runat="server" />

      <br /><br />

      <asp:Label id="Label1" runat="server"/>

   </form>
</body>
</html>

注釈

コントロールに VisibleDate 表示する月をプログラムで設定するには、 プロパティを Calendar 使用します。 指定した日付には、表示する月の任意の日付を指定できますが、月の最初の日付を使用するのが一般的です。 このプロパティは、 オブジェクトを System.DateTime 使用して設定されます。

イベントが VisibleDate 発生する前に、 VisibleMonthChanged プロパティが更新されます。 カスタム OnVisibleMonthChanged イベント ハンドラーを指定して、 プロパティを VisibleDate 設定し、自動的に生成された値をオーバーライドできます。

適用対象

こちらもご覧ください