Calendar.VisibleDate Propiedad

Definición

Obtiene o establece el valor de DateTime que especifica el mes que se va a mostrar en el control 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

Valor de propiedad

Un objeto DateTime que especifica el mes que se muestra en el control Calendar. El valor predeterminado es DateTime.MinValue, que muestra el mes que contiene la fecha especificada por TodaysDate.

Atributos

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar la VisibleDate propiedad para establecer mediante programación el valor que determina el mes que se muestra en el Calendar control .

<%@ 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>

Comentarios

Utilice la VisibleDate propiedad para establecer mediante programación el mes que se mostrará en el Calendar control. La fecha especificada puede ser cualquier fecha del mes que desee mostrar, aunque es habitual usar la primera fecha del mes. Esta propiedad se establece mediante un System.DateTime objeto .

La VisibleDate propiedad se actualiza antes de que se genere el VisibleMonthChanged evento. Puede proporcionar un controlador de eventos personalizado OnVisibleMonthChanged para establecer la VisibleDate propiedad e invalidar el valor generado automáticamente.

Se aplica a

Consulte también