GridViewSortEventArgsとは? わかりやすく解説

GridViewSortEventArgs クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

Sorting イベントデータ提供します

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Class GridViewSortEventArgs
    Inherits CancelEventArgs
Dim instance As GridViewSortEventArgs
public class GridViewSortEventArgs : CancelEventArgs
public ref class GridViewSortEventArgs : public
 CancelEventArgs
public class GridViewSortEventArgs extends
 CancelEventArgs
public class GridViewSortEventArgs extends
 CancelEventArgs
解説解説

GridView コントロールは、Sort ボタン (CommandName プロパティが "Sort" に設定されボタン) がクリックされた場合に、GridView コントロール並べ替え操作処理する前に Sorting イベント発生させます。これにより、このイベント発生するたびにカスタム ルーチン (並べ替え操作キャンセルするなど) を実行するイベント処理メソッドを提供できます

メモメモ

CommandName プロパティが "Sort" に設定されGridView コントロール内のすべてのボタンSorting イベント発生させますが、一般的に Sort ボタンGridView コントロールヘッダー行に表示されます。

GridViewSortEventArgs オブジェクトイベント処理メソッド渡されることにより、GridView コントロール並べ替え使用する並べ替え式や並べ替え方向指定または確認できます並べ替え式を確認するには、SortExpression プロパティ使用します並べ替え方向確認するには、SortDirection プロパティ使用しますCancel プロパティtrue設定して並べ替え操作キャンセルすることもできます

イベント処理詳細については、「イベント利用」を参照してください

GridViewSortEventArgsインスタンス初期プロパティ値の一覧については、GridViewSelectEventArgs コンストラクタトピック参照してください

使用例使用例

イベント処理メソッド渡されGridViewSortEventArgs オブジェクト使用してユーザーGridView コントロール内の Contract 列を並べ替えようとしたときに並べ替え操作キャンセルする方法次の例に示します

<%@ Page language="VB" %>

<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>
  <body>
    <form 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>

<%@ Page language="C#" %>

<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>
  <body>
    <form 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>

.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.EventArgs
     System.ComponentModel.CancelEventArgs
      System.Web.UI.WebControls.GridViewSortEventArgs
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
GridViewSortEventArgs メンバ
System.Web.UI.WebControls 名前空間
GridView クラス
GridViewSortEventHandler
GridView.AllowSorting プロパティ
GridView.Sorted イベント
GridView.Sorting イベント
その他の技術情報
イベント利用

GridViewSortEventArgs コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

GridViewSortEventArgs クラス新しインスタンス初期化します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Sub New ( _
    sortExpression As String, _
    sortDirection As SortDirection _
)
Dim sortExpression As String
Dim sortDirection As SortDirection

Dim instance As New GridViewSortEventArgs(sortExpression,
 sortDirection)
public GridViewSortEventArgs (
    string sortExpression,
    SortDirection sortDirection
)
public:
GridViewSortEventArgs (
    String^ sortExpression, 
    SortDirection sortDirection
)
public GridViewSortEventArgs (
    String sortExpression, 
    SortDirection sortDirection
)
public function GridViewSortEventArgs (
    sortExpression : String, 
    sortDirection : SortDirection
)

パラメータ

sortExpression

コントロール内の項目の並べ替え使用する並べ替え式。

sortDirection

コントロール内の項目を並べ替える方向指定する SortDirection。

解説解説

このコンストラクタ使用してGridViewSortEventArgs クラス新しインスタンス初期化します。

GridViewSortEventArgsインスタンス初期プロパティ値を次の表に示します

プロパティ

初期値

SortDirection

sortDirection パラメータの値。

SortExpression

sortExpression パラメータの値。

メモメモ

このコンストラクタは、主にコントロール開発者イベント発生させる場合使用します

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
GridViewSortEventArgs クラス
GridViewSortEventArgs メンバ
System.Web.UI.WebControls 名前空間
SortDirection
SortExpression

GridViewSortEventArgs プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ Cancel  イベントキャンセルするかどうかを示す値を取得または設定します。 ( CancelEventArgs から継承されます。)
パブリック プロパティ SortDirection GridView コントロール並べ替える方向取得または設定します
パブリック プロパティ SortExpression GridView コントロール内の項目の並べ替え使用する式を取得または設定します
参照参照

関連項目

GridViewSortEventArgs クラス
System.Web.UI.WebControls 名前空間
GridView クラス
GridViewSortEventHandler
GridView.AllowSorting プロパティ
GridView.Sorted イベント
GridView.Sorting イベント

その他の技術情報

イベント利用

GridViewSortEventArgs メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

GridViewSortEventArgs クラス
System.Web.UI.WebControls 名前空間
GridView クラス
GridViewSortEventHandler
GridView.AllowSorting プロパティ
GridView.Sorted イベント
GridView.Sorting イベント

その他の技術情報

イベント利用

GridViewSortEventArgs メンバ

Sorting イベントデータ提供します

GridViewSortEventArgs データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド GridViewSortEventArgs GridViewSortEventArgs クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ Cancel  イベントキャンセルするかどうかを示す値を取得または設定します。(CancelEventArgs から継承されます。)
パブリック プロパティ SortDirection GridView コントロール並べ替える方向取得または設定します
パブリック プロパティ SortExpression GridView コントロール内の項目の並べ替え使用する式を取得または設定します
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

GridViewSortEventArgs クラス
System.Web.UI.WebControls 名前空間
GridView クラス
GridViewSortEventHandler
GridView.AllowSorting プロパティ
GridView.Sorted イベント
GridView.Sorting イベント

その他の技術情報

イベント利用


このページでは「.NET Framework クラス ライブラリ リファレンス」からGridViewSortEventArgsを検索した結果を表示しています。
Weblioに収録されているすべての辞書からGridViewSortEventArgsを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からGridViewSortEventArgs を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「GridViewSortEventArgs」の関連用語

GridViewSortEventArgsのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



GridViewSortEventArgsのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS