다음을 통해 공유


GridViewSortEventArgs 클래스

정의

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

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

예제

다음 예제에서는 사용자가 컨트롤에서 GridViewSortEventArgs 주소 열을 GridView 정렬하려고 할 때 이벤트 처리 메서드에 전달된 개체를 사용하여 정렬 작업을 취소하는 방법을 보여 줍니다.


<%@ 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">
  
  void CustomersGridView_Sorting(Object sender, GridViewSortEventArgs e)
  {
    // Cancel the sorting operation if the user attempts
    // to sort by address.
    if (e.SortExpression == "Address")
    {
      e.Cancel = true;
      Message.Text = "You cannot sort by address.";
      SortInformationLabel.Text = "";
    }
    else
    {
      Message.Text = "";
    }
  }

  void CustomersGridView_Sorted(Object sender, EventArgs e)
  {
    // Display the sort expression and sort direction.
    SortInformationLabel.Text = "Sorting by " +
      CustomersGridView.SortExpression.ToString() +
      " in " + CustomersGridView.SortDirection.ToString() +
      " order.";
  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>GridView Sorting Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView Sorting Example</h3>

      <asp:label id="Message"
        forecolor="Red"
        runat="server"/>
        
      <br/>
        
      <asp:label id="SortInformationLabel"
        forecolor="Navy"
        runat="server"/>
                
      <br/>  

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSource" 
        autogeneratecolumns="true"
        allowpaging="true"
        emptydatatext="No data available." 
        allowsorting="true"
        onsorting="CustomersGridView_Sorting"
        onsorted="CustomersGridView_Sorted"  
        runat="server">
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!-- from the Web.config file.                            -->
      <asp:sqldatasource id="CustomersSource"
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
        
    </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">
  
  Sub CustomersGridView_Sorting(sender As Object, e As GridViewSortEventArgs)
  
    ' Cancel the sorting operation if the user attempts
    ' to sort by address.
    If e.SortExpression = "Address" Then
    
      e.Cancel = True
      Message.Text = "You cannot sort by address."
      SortInformationLabel.Text = ""
    
    Else
    
      Message.Text = ""
      
    End If
    
  End Sub

  Sub CustomersGridView_Sorted(ByVal sender As Object, ByVal e As EventArgs)
 
    ' Display the sort expression and sort direction.
    SortInformationLabel.Text = "Sorting by " & _
      CustomersGridView.SortExpression.ToString() & _
      " in " & CustomersGridView.SortDirection.ToString() & _
      " order."
    
  End Sub
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>GridView Sorted and Sorting Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView Sorted and Sorting Example</h3>

      <asp:label id="Message"
        forecolor="Red"
        runat="server"/>
        
      <br/>
        
      <asp:label id="SortInformationLabel"
        forecolor="Navy"
        runat="server"/>
                
      <br/>  

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSource" 
        autogeneratecolumns="true"
        allowpaging="true"
        emptydatatext="No data available." 
        allowsorting="true"
        onsorting="CustomersGridView_Sorting"
        onsorted="CustomersGridView_Sorted"  
        runat="server">
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!-- from the Web.config file.                            -->
      <asp:sqldatasource id="CustomersSource"
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
        
    </form>
  </body>
</html>

설명

GridView 정렬 단추(속성이 Sorting "정렬"로 설정된 단추CommandName)를 클릭할 때 컨트롤이 정렬 작업을 처리하기 전에 컨트롤이 GridView 이벤트를 발생합니다. 이렇게 하면 이 이벤트가 발생할 때마다 정렬 작업 취소와 같은 사용자 지정 루틴을 수행하는 이벤트 처리 메서드를 제공할 수 있습니다.

메모

속성이 GridView "Sort"로 설정된 컨트롤 CommandName 내의 단추가 있으면 이벤트가 발생 Sorting 하지만 정렬 단추는 일반적으로 컨트롤의 GridView 머리글 행에 나타납니다.

GridViewSortEventArgs 개체가 이벤트 처리 메서드에 전달되므로 컨트롤을 정렬 GridView 할 정렬 식과 정렬 방향을 지정하거나 확인할 수 있습니다. 정렬 식을 확인하려면 속성을 사용합니다 SortExpression . 정렬 방향을 확인하려면 속성을 사용합니다 SortDirection . 속성을 .로 설정 Cancel 하여 정렬 작업을 취소할 true수도 있습니다.

이벤트를 처리하는 방법에 대한 자세한 내용은 이벤트 처리 및 발생을 참조하세요.

인스턴스 GridViewSortEventArgs의 초기 속성 값 목록은 생성자를 참조 GridViewSelectEventArgs 하세요.

생성자

Name Description
GridViewSortEventArgs(String, SortDirection)

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

속성

Name Description
Cancel

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

(다음에서 상속됨 CancelEventArgs)
SortDirection

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

SortExpression

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

메서드

Name Description
Equals(Object)

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

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

기본 해시 함수로 사용됩니다.

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

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

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

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

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

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

(다음에서 상속됨 Object)

적용 대상

추가 정보