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.

AGridViewSortEventArgsを並べ替える対象の式と並べ替えの方向を指定するか、並べ替えを決定することができるイベント処理メソッドにオブジェクトが渡される、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)

適用対象

こちらもご覧ください