GridViewSortEventArgs GridViewSortEventArgs GridViewSortEventArgs GridViewSortEventArgs Class

정의

Sorting 이벤트에 대한 데이터를 제공합니다.Provides data for the Sorting event.

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

예제

다음 예제에서는 사용 하는 방법에 설명 합니다 GridViewSortEventArgs 사용자 주소 열을 정렬 하려고 할 때 정렬 작업을 취소 하는 이벤트 처리 메서드에 전달 된 개체를 GridView 제어 합니다.The following example demonstrates how to use the GridViewSortEventArgs object passed to the event-handling method to cancel the sorting operation when the user attempts to sort the address column in a GridView control.


<%@ 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 컨트롤이 정렬 작업을 처리 합니다.The GridView control raises the Sorting event when a Sort button (a button with its CommandName property set to "Sort") is clicked, but before the GridView control handles the sort operation. 이 옵션을 사용 하면이 이벤트가 발생할 때마다 정렬 작업을 취소 하는 등 사용자 지정 루틴을 수행 하는 이벤트 처리 메서드를 제공할 수 있습니다.This allows you to provide an event-handling method that performs a custom routine, such as canceling the sorting operation, whenever this event occurs.

참고

내의 모든 단추를 GridView 컨트롤 해당 CommandName "Sort"로 설정 하는 속성에서 발생 합니다 Sorting 이벤트 정렬 단추의 머리글 행에 일반적으로 표시를 GridView 컨트롤.Although any button within a GridView control with its CommandName property set to "Sort" will raise the Sorting event, Sort buttons typically appear in the header row of a GridView control.

A GridViewSortEventArgs 개체는 정렬 식과 정렬 방향을를 지정 하거나 정렬을 확인할 수 있는 이벤트 처리 메서드에 전달 되며는 GridView 제어 합니다.A GridViewSortEventArgs object is passed to the event-handling method, which allows you to specify or determine the sort expression and sort direction in which to sort the GridView control. 정렬 식을 확인 하려면 사용 된 SortExpression 속성입니다.To determine the sort expression, use the SortExpression property. 정렬 방향을 확인 하려면 사용 된 SortDirection 속성입니다.To determine the sort direction, use the SortDirection property. 설정 하 여 정렬 작업을 취소할 수도 있습니다는 Cancel 속성을 true입니다.You can also cancel a sorting operation by setting the Cancel property to true.

이벤트를 처리 하는 방법에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.For more information about how to handle events, see Handling and Raising Events.

인스턴스의 초기 속성 값의 목록을 GridViewSortEventArgs, 참조는 GridViewSelectEventArgs 생성자입니다.For a list of initial property values for an instance of GridViewSortEventArgs, see the GridViewSelectEventArgs constructor.

생성자

GridViewSortEventArgs(String, SortDirection) GridViewSortEventArgs(String, SortDirection) GridViewSortEventArgs(String, SortDirection) GridViewSortEventArgs(String, SortDirection)

GridViewSortEventArgs 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the GridViewSortEventArgs class.

속성

Cancel Cancel Cancel Cancel

이벤트를 취소해야 할지 여부를 나타내는 값을 가져오거나 설정합니다.Gets or sets a value indicating whether the event should be canceled.

(Inherited from CancelEventArgs)
SortDirection SortDirection SortDirection SortDirection

GridView 컨트롤을 정렬할 방향을 가져오거나 설정합니다.Gets or sets the direction in which to sort the GridView control.

SortExpression SortExpression SortExpression SortExpression

GridView 컨트롤의 항목을 정렬하는 데 사용되는 식을 가져오거나 설정합니다.Gets or sets the expression used to sort the items in the GridView control.

메서드

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

지정한 개체와 현재 개체가 같은지 여부를 확인합니다.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

기본 해시 함수로 작동합니다.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

현재 인스턴스의 Type을 가져옵니다.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

현재 개체를 나타내는 문자열을 반환합니다.Returns a string that represents the current object.

(Inherited from Object)

적용 대상

추가 정보