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 자동으로 생성된 값을 재정의할 수 있습니다.

적용 대상

추가 정보