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 "Sort"로 설정 하는 속성)를 클릭 하기 전에 GridView 컨트롤이 정렬 작업을 처리 합니다. 이 옵션을 사용 하면이 이벤트가 발생할 때마다 정렬 작업을 취소 하는 등 사용자 지정 루틴을 수행 하는 이벤트 처리 메서드를 제공할 수 있습니다.

참고

내의 모든 단추를 GridView 컨트롤 해당 CommandName "Sort"로 설정 하는 속성에서 발생 합니다 Sorting 이벤트 정렬 단추의 머리글 행에 일반적으로 표시를 GridView 컨트롤.

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

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

인스턴스의 초기 속성 값의 목록을 GridViewSortEventArgs, 참조는 GridViewSelectEventArgs 생성자입니다.

생성자

GridViewSortEventArgs(String, SortDirection)

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

속성

Cancel

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

(다음에서 상속됨 CancelEventArgs)
SortDirection

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

SortExpression

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

메서드

Equals(Object)

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

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

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

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

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

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

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

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

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

(다음에서 상속됨 Object)

적용 대상

추가 정보