다음을 통해 공유


ListViewSortEventArgs 클래스

정의

Sorting 이벤트에 대한 데이터를 제공합니다.

public ref class ListViewSortEventArgs : System::ComponentModel::CancelEventArgs
public class ListViewSortEventArgs : System.ComponentModel.CancelEventArgs
type ListViewSortEventArgs = class
    inherit CancelEventArgs
Public Class ListViewSortEventArgs
Inherits CancelEventArgs
상속
ListViewSortEventArgs

예제

다음 예제에서는 사용 하는 방법의 ListViewSortEventArgs 정렬 되는 열 및 정렬 방향을 표시 하는 개체입니다.

<%@ Page language="C#" %>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
<script runat="server">
  //<Snippet2>
  void ContactsListView_Sorting(Object sender, ListViewSortEventArgs e)
  {
    // Check the sort direction to set the image URL accordingly.
    string imgUrl;
    if (e.SortDirection == SortDirection.Ascending)
      imgUrl = "~/images/ascending.gif";
    else
      imgUrl = "~/images/descending.gif";
      
    // Check which field is being sorted
    // to set the visibility of the image controls.
    Image sortImage1 = (Image) ContactsListView.FindControl("SortImage1");
    Image sortImage2 = (Image)ContactsListView.FindControl("SortImage2");
    Image sortImage3 = (Image)ContactsListView.FindControl("SortImage3");
    switch (e.SortExpression)
    {
      case "FirstName":
        sortImage1.Visible = true;
        sortImage1.ImageUrl = imgUrl;
        sortImage2.Visible = false;
        sortImage3.Visible = false;
        break;
      case "LastName":
        sortImage1.Visible = false;
        sortImage2.Visible = true;
        sortImage2.ImageUrl = imgUrl;
        sortImage3.Visible = false;
        break;
      case "EmailAddress":
        sortImage1.Visible = false;
        sortImage2.Visible = false;
        sortImage3.Visible = true;
        sortImage3.ImageUrl = imgUrl;
        break;
    }
  }
  //</Snippet2>
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>ListView Sorting Example</title>
    <style type="text/css">
      body  { font: 10pt Trebuchet MS, Arial, Tahoma; }
      td { border: 1px solid #E6E6FA; }
      .header {	background: #B0C4DE; }
      .alternatingItem { background: #edf5fd; }
    </style>
  </head>
  <body>
    <form id="form1" runat="server">
        
      <h3>ListView Sorting Example</h3>
      
      <asp:ListView ID="ContactsListView" 
        DataSourceID="ContactsDataSource" 
        OnSorting="ContactsListView_Sorting"
        runat="server">
        <LayoutTemplate>
          <table width="640px" runat="server" id="tblContacts">
            <tr class="header" align="center" runat="server">
              <td>
                <asp:LinkButton runat="server" ID="SortByFirstNameButton"
                  CommandName="Sort" Text="First Name" 
                  CommandArgument="FirstName"/>
                <asp:Image runat="server" ID="SortImage1" 
                  ImageUrl="~/images/ascending.gif" Visible="false" />
              </td>
              <td>
                <asp:LinkButton runat="server" ID="SortByLastNameButton"
                  CommandName="Sort" Text="Last Name"
                  CommandArgument="LastName" />
                <asp:Image runat="server" ID="SortImage2" 
                  ImageUrl="~/images/ascending.gif" Visible="false" />
              </td>
              <td>
                <asp:LinkButton runat="server" ID="SortByEmailButton"
                  CommandName="Sort" Text="Email Address" 
                  CommandArgument="EmailAddress" />
                <asp:Image runat="server" ID="SortImage3" 
                  ImageUrl="~/images/ascending.gif" Visible="false" />
              </td>
            </tr>
            <tr runat="server" id="itemPlaceholder" />
          </table>
          <asp:DataPager runat="server" ID="PeopleDataPager" PageSize="12">
            <Fields>
              <asp:NextPreviousPagerField 
                ShowFirstPageButton="true" ShowLastPageButton="true"
                FirstPageText="|&lt;&lt; " LastPageText=" &gt;&gt;|"
                NextPageText=" &gt; " PreviousPageText=" &lt; " />
            </Fields>
          </asp:DataPager>
        </LayoutTemplate>
        <ItemTemplate>
          <tr runat="server">
            <td>
              <asp:Label ID="FirstNameLabel" runat="server" Text='<%#Eval("FirstName") %>' />
            </td>
            <td>
              <asp:Label ID="LastNameLabel" runat="server" Text='<%#Eval("LastName") %>' />
            </td>
            <td>
              <asp:Label ID="EmailLabel" runat="server" Text='<%#Eval("EmailAddress") %>' />
            </td>
          </tr>
        </ItemTemplate>
        <AlternatingItemTemplate>
          <tr class="alternatingItem" runat="server">
            <td>
              <asp:Label ID="FirstNameLabel" runat="server" Text='<%#Eval("FirstName") %>' />
            </td>
            <td>
              <asp:Label ID="LastNameLabel" runat="server" Text='<%#Eval("LastName") %>' />
            </td>
            <td>
              <asp:Label ID="EmailLabel" runat="server" Text='<%#Eval("EmailAddress") %>' />
            </td>
          </tr>
        </AlternatingItemTemplate>
      </asp:ListView>
      
      <!-- This example uses Microsoft SQL Server and connects    -->
      <!-- to the AdventureWorks sample database. Use an ASP.NET  -->
      <!-- expression to retrieve the connection string value     -->
      <!-- from the Web.config file.                              -->
      <asp:SqlDataSource ID="ContactsDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
        SelectCommand="SELECT [ContactID], [FirstName], [LastName], [EmailAddress] 
          FROM Person.Contact" >
      </asp:SqlDataSource>
      
    </form>
  </body>
</html>
<%@ Page language="VB" %>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
<script runat="server">
 '<Snippet2>
  Sub ContactsListView_Sorting(ByVal sender As Object, ByVal e As ListViewSortEventArgs) 
  
    ' Check the sort direction to set the image URL accordingly.
    Dim imgUrl As String
    If e.SortDirection = SortDirection.Ascending Then
      imgUrl = "~/images/ascending.gif"
    Else
      imgUrl = "~/images/descending.gif"
    End If
    
    ' Check which field is being sorted
    ' to set the visibility of the image controls.
    Dim sortImage1 As Image = CType(ContactsListView.FindControl("SortImage1"), Image)
    Dim sortImage2 As Image = CType(ContactsListView.FindControl("SortImage2"), Image)
    Dim sortImage3 As Image = CType(ContactsListView.FindControl("SortImage3"), Image)
    
    Select Case e.SortExpression
      Case "FirstName"
        sortImage1.Visible = True
        sortImage1.ImageUrl = imgUrl
        sortImage2.Visible = False
        sortImage3.Visible = False
      Case "LastName"
        sortImage1.Visible = False
        sortImage2.Visible = True
        sortImage2.ImageUrl = imgUrl
        sortImage3.Visible = False
      Case "EmailAddress"
        sortImage1.Visible = False
        sortImage2.Visible = False
        sortImage3.Visible = True
        sortImage3.ImageUrl = imgUrl
    End Select
    
  End Sub
  '</Snippet2>
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>ListView Sorting Example</title>
    <style type="text/css">
      body  { font: 10pt Trebuchet MS, Arial, Tahoma; }
      td { border: 1px solid #E6E6FA; }
      .header {	background: #B0C4DE; }
      .alternatingItem { background: #edf5fd; }
    </style>
  </head>
  <body>
    <form id="form1" runat="server">
        
      <h3>ListView Sorting Example</h3>
      
      <asp:ListView ID="ContactsListView" 
        DataSourceID="ContactsDataSource" 
        OnSorting="ContactsListView_Sorting"
        runat="server">
        <LayoutTemplate>
          <table width="640px" runat="server" id="tblContacts">
            <tr class="header" align="center" runat="server">
              <td>
                <asp:LinkButton runat="server" ID="SortByFirstNameButton"
                  CommandName="Sort" Text="First Name" 
                  CommandArgument="FirstName"/>
                <asp:Image runat="server" ID="SortImage1" 
                  ImageUrl="~/images/ascending.gif" Visible="false" />
              </td>
              <td>
                <asp:LinkButton runat="server" ID="SortByLastNameButton"
                  CommandName="Sort" Text="Last Name"
                  CommandArgument="LastName" />
                <asp:Image runat="server" ID="SortImage2" 
                  ImageUrl="~/images/ascending.gif" Visible="false" />
              </td>
              <td>
                <asp:LinkButton runat="server" ID="SortByEmailButton"
                  CommandName="Sort" Text="Email Address" 
                  CommandArgument="EmailAddress" />
                <asp:Image runat="server" ID="SortImage3" 
                  ImageUrl="~/images/ascending.gif" Visible="false" />
              </td>
            </tr>
            <tr runat="server" id="itemPlaceholder" />
          </table>
          <asp:DataPager runat="server" ID="PeopleDataPager" PageSize="12">
            <Fields>
              <asp:NextPreviousPagerField 
                ShowFirstPageButton="true" ShowLastPageButton="true"
                FirstPageText="|&lt;&lt; " LastPageText=" &gt;&gt;|"
                NextPageText=" &gt; " PreviousPageText=" &lt; " />
            </Fields>
          </asp:DataPager>
        </LayoutTemplate>
        <ItemTemplate>
          <tr runat="server">
            <td>
              <asp:Label ID="FirstNameLabel" runat="server" Text='<%#Eval("FirstName") %>' />
            </td>
            <td>
              <asp:Label ID="LastNameLabel" runat="server" Text='<%#Eval("LastName") %>' />
            </td>
            <td>
              <asp:Label ID="EmailLabel" runat="server" Text='<%#Eval("EmailAddress") %>' />
            </td>
          </tr>
        </ItemTemplate>
        <AlternatingItemTemplate>
          <tr class="alternatingItem" runat="server">
            <td>
              <asp:Label ID="FirstNameLabel" runat="server" Text='<%#Eval("FirstName") %>' />
            </td>
            <td>
              <asp:Label ID="LastNameLabel" runat="server" Text='<%#Eval("LastName") %>' />
            </td>
            <td>
              <asp:Label ID="EmailLabel" runat="server" Text='<%#Eval("EmailAddress") %>' />
            </td>
          </tr>
        </AlternatingItemTemplate>
      </asp:ListView>
      
      <!-- This example uses Microsoft SQL Server and connects    -->
      <!-- to the AdventureWorks sample database. Use an ASP.NET  -->
      <!-- expression to retrieve the connection string value     -->
      <!-- from the Web.config file.                              -->
      <asp:SqlDataSource ID="ContactsDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
        SelectCommand="SELECT [ContactID], [FirstName], [LastName], [EmailAddress] 
          FROM Person.Contact" >
      </asp:SqlDataSource>
      
    </form>
  </body>
</html>

설명

합니다 ListView 를 발생 시킵니다 합니다 Sorting 정렬 단추를 클릭할 때 이벤트를 하기 전에 ListView 컨트롤이 정렬 작업을 처리 합니다. (정렬 단추는 단추입니다 CommandName 속성이 "정렬"로 설정 합니다.) 그러면 정렬 식을 사용자 지정 등이 이벤트가 발생할 때마다 사용자 지정 루틴을 수행 하는 이벤트 처리 메서드를 제공할 수 있습니다.

ListViewSortEventArgs 개체 이벤트 처리 메서드에 전달 됩니다. 이 개체에 대 한 정렬 식과 정렬 방향을 확인 또는 지정할 수 있습니다는 ListView 제어 합니다. 정렬 식을 확인 하려면 사용 된 SortExpression 속성입니다. 정렬 방향을 확인 하려면 사용 된 SortDirection 속성입니다. 설정 하 여 정렬 작업을 취소할 수도 있습니다는 Cancel 속성을 true입니다.

ListViewSortEventArgs 클래스의 인스턴스에 대한 초기 속성 값 목록은 ListViewSelectEventArgs 생성자를 참조하십시오.

생성자

ListViewSortEventArgs(String, SortDirection)

ListViewSortEventArgs 클래스의 새 인스턴스를 초기화합니다.

속성

Cancel

이벤트를 취소해야 할지 여부를 나타내는 값을 가져오거나 설정합니다.

(다음에서 상속됨 CancelEventArgs)
SortDirection

ListView 컨트롤을 정렬할 방향을 가져오거나 설정합니다.

SortExpression

ListView 컨트롤의 항목을 정렬하는 데 사용되는 식을 가져오거나 설정합니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보