Calendar.OnSelectionChanged 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
SelectionChanged 컨트롤의 Calendar 이벤트를 발생시키고 사용자가 SelectionChanged 이벤트에 대한 사용자 지정 처리기를 제공할 수 있도록 합니다.
protected:
virtual void OnSelectionChanged();
protected virtual void OnSelectionChanged ();
abstract member OnSelectionChanged : unit -> unit
override this.OnSelectionChanged : unit -> unit
Protected Overridable Sub OnSelectionChanged ()
예제
다음 코드 예제를 지정 하 고 컨트롤에서 Calendar 선택한 항목 수를 표시 하는 이벤트에 대 한 SelectionChanged 처리기를 코딩 하는 방법을 보여 줍니다.
<%@ 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 SelectionChanged Example</title>
<script runat="server">
void Selection_Change(Object sender, EventArgs e)
{
// Clear the current text.
Message.Text = "";
// Iterate through the SelectedDates collection and display the
// dates selected in the Calendar control.
foreach(DateTime day in Calendar1.SelectedDates)
{
Message.Text += day.Date.ToShortDateString() + "<br />";
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>Calendar SelectionChanged Example</h3>
Select dates on the Calendar control.<br /><br />
<asp:Calendar ID="Calendar1" runat="server"
SelectionMode="DayWeekMonth"
ShowGridLines="True"
OnSelectionChanged="Selection_Change">
<SelectedDayStyle BackColor="Yellow"
ForeColor="Red">
</SelectedDayStyle>
</asp:Calendar>
<hr />
<table border="1">
<tr style="background-color:silver">
<th>
Selected Dates:
</th>
</tr>
<tr>
<td>
<asp:Label id="Message"
Text="No dates selected."
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 SelectionChanged Example</title>
<script runat="server">
Sub Selection_Change(sender As Object, e As EventArgs)
' Clear the current text.
Message.Text = ""
' Iterate through the SelectedDates collection and display the
' dates selected in the Calendar control.
Dim day As DateTime
For Each day In Calendar1.SelectedDates
Message.Text &= day.Date.ToShortDateString() & "<br />"
Next
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>Calendar SelectionChanged Example</h3>
Select dates on the Calendar control.<br /><br />
<asp:Calendar ID="Calendar1" runat="server"
SelectionMode="DayWeekMonth"
ShowGridLines="True"
OnSelectionChanged="Selection_Change">
<SelectedDayStyle BackColor="Yellow"
ForeColor="Red">
</SelectedDayStyle>
</asp:Calendar>
<hr />
<table border="1">
<tr style="background-color:silver">
<th>
Selected Dates:
</th>
</tr>
<tr>
<td>
<asp:Label id="Message"
Text="No dates selected."
runat="server"/>
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ 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 SelectionChanged Example</title>
<script runat="server">
void Selection_Change(Object sender, EventArgs e)
{
// Clear the current text.
Message.Text = "";
// Iterate through the SelectedDates collection and display the
// dates selected in the Calendar control.
foreach(DateTime day in Calendar1.SelectedDates)
{
Message.Text += day.Date.ToShortDateString() + "<br />";
}
}
void Page_Load(Object sender, EventArgs e)
{
// Manually register the event-handling method for the
// SelectionChanged event of the Calendar control.
Calendar1.SelectionChanged += new EventHandler(this.Selection_Change);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>Calendar SelectionChanged Example</h3>
Select a day, week, or month on the Calendar control.<br /><br />
<asp:Calendar ID="Calendar1" runat="server"
SelectionMode="DayWeekMonth"
ShowGridLines="True">
<SelectedDayStyle BackColor="Yellow"
ForeColor="Red">
</SelectedDayStyle>
</asp:Calendar>
<hr />
<table border="1">
<tr style="background-color:silver">
<th>
Selected dates
</th>
</tr>
<tr>
<td>
<asp:Label id="Message"
Text="No dates selected."
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 SelectionChanged Example</title>
<script runat="server">
Sub Selection_Change(sender As Object, e As EventArgs)
' Clear the current text.
Message.Text = ""
' Iterate through the SelectedDates collection and display the
' dates selected in the Calendar control.
Dim day As DateTime
For Each day In Calendar1.SelectedDates
Message.Text &= day.Date.ToShortDateString() & "<br />"
Next
End Sub
Sub Page_Load(sender As Object, e As EventArgs)
' Manually register the event-handling method for the
' SelectionChanged event of the Calendar control.
AddHandler Calendar1.SelectionChanged, AddressOf Selection_Change
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>Calendar SelectionChanged Example</h3>
Select a day, week, or month on the Calendar control.<br /><br />
<asp:Calendar ID="Calendar1" runat="server"
SelectionMode="DayWeekMonth"
ShowGridLines="True">
<SelectedDayStyle BackColor="Yellow"
ForeColor="Red">
</SelectedDayStyle>
</asp:Calendar>
<hr />
<table border="1">
<tr style="background-color:silver">
<th>
Selected Dates:
</th>
</tr>
<tr>
<td>
<asp:Label id="Message"
Text="No dates selected."
runat="server"/>
</td>
</tr>
</table>
</form>
</body>
</html>
설명
이 SelectionChanged 이벤트는 사용자가 날짜 선택기 컨트롤을 클릭하여 하루, 일주일 또는 전체 월을 선택할 때 발생합니다.
이벤트가 발생하면 대리자를 통해 이벤트 처리기가 호출됩니다. 자세한 내용은 이벤트 처리 및 발생합니다.
또한 OnSelectionChanged 메서드를 사용하면 파생 클래스가 대리자를 연결하지 않고도 이벤트를 처리할 수 있습니다. 이는 파생 클래스에서 이벤트를 처리하는 기본 방법입니다.
상속자 참고
파생 클래스에서 OnSelectionChanged()를 재정의하는 경우 등록된 대리자가 이벤트를 받도록 기본 클래스의 OnSelectionChanged() 메서드를 호출해야 합니다.
적용 대상
추가 정보
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET