ASP.NET

23.C# ASP.NET - Calendar(달력) [WebStandardControl]

Godffs 2009. 10. 7. 11:27
반응형
Calendar(달력) 컨트롤에 관한 예제입니다.

FrmCalendar.aspx

<div>

   <asp:Calendar ID="Calendar1" runat="server"

       onselectionchanged="Calendar1_SelectionChanged"></asp:Calendar>

   <hr />

   <asp:Label ID="lblDate" runat="server" Text=""></asp:Label>

   <hr />

  

   <asp:Calendar ID="Calendar2" runat="server"

       SelectionMode="DayWeekMonth"

       onselectionchanged="Calendar2_SelectionChanged"></asp:Calendar>

   <asp:Label ID="lblDates" runat="server" Text=""></asp:Label>

   <br />

  

   <asp:Calendar ID="Calendar3" runat="server" BackColor="#FFFFCC"

       BorderColor="#FFCC66" BorderWidth="1px"

           DayNameFormat="Shortest"

          

       Font-Names="Verdana" Font-Size="8pt"

           ForeColor="#663399" Height="310px"

          

       NextMonthText="다음달" PrevMonthText="이전달"

           ShowGridLines="True" Width="607px">

          

       <SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />

       <SelectorStyle BackColor="#FFCC66" />

       <TodayDayStyle BackColor="#FFCC66" ForeColor="White" />

       <OtherMonthDayStyle ForeColor="#CC9966" />

       <NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />

       <DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />

       <TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt"

           ForeColor="#FFFFCC" />

   </asp:Calendar>  

</div>


FrmCalendar.aspx.cs

protected void Calendar1_SelectionChanged(object sender, EventArgs e)

{

   // 현재 선택된 날짜/시간값을 출력

   this.lblDate.Text = Calendar1.SelectedDate.ToLongDateString();

}

 

protected void Calendar2_SelectionChanged(object sender, EventArgs e)

{

   // 현재 선택된 범위의 날짜값을 출력

   string s = "";

   foreach (DateTime item in Calendar2.SelectedDates)

    {

       s += item.ToShortDateString() + "<br />";                   

    }

   lblDates.Text = s;

}


결과화면

[그림23-1]



반응형