GridViewSortEventArgs クラス
アセンブリ: System.Web (system.web.dll 内)


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>


System.EventArgs
System.ComponentModel.CancelEventArgs
System.Web.UI.WebControls.GridViewSortEventArgs


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


GridViewSortEventArgs コンストラクタ
アセンブリ: System.Web (system.web.dll 内)

Dim sortExpression As String Dim sortDirection As SortDirection Dim instance As New GridViewSortEventArgs(sortExpression, sortDirection)

このコンストラクタを使用して、GridViewSortEventArgs クラスの新しいインスタンスを初期化します。
GridViewSortEventArgs のインスタンスの初期プロパティ値を次の表に示します。
![]() |
---|

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


GridViewSortEventArgs プロパティ

名前 | 説明 | |
---|---|---|
![]() | Cancel | イベントをキャンセルするかどうかを示す値を取得または設定します。 ( CancelEventArgs から継承されます。) |
![]() | SortDirection | GridView コントロールを並べ替える方向を取得または設定します。 |
![]() | SortExpression | GridView コントロール内の項目の並べ替えに使用する式を取得または設定します。 |

GridViewSortEventArgs メソッド

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

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


名前 | 説明 | |
---|---|---|
![]() | Cancel | イベントをキャンセルするかどうかを示す値を取得または設定します。(CancelEventArgs から継承されます。) |
![]() | SortDirection | GridView コントロールを並べ替える方向を取得または設定します。 |
![]() | SortExpression | GridView コントロール内の項目の並べ替えに使用する式を取得または設定します。 |

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

- GridViewSortEventArgsのページへのリンク