GridViewSortEventArgs 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
为 Sorting 事件提供数据。
public ref class GridViewSortEventArgs : System::ComponentModel::CancelEventArgs
public class GridViewSortEventArgs : System.ComponentModel.CancelEventArgs
type GridViewSortEventArgs = class
inherit CancelEventArgs
Public Class GridViewSortEventArgs
Inherits CancelEventArgs
- 继承
示例
下面的示例演示当用户尝试对控件中的GridView地址列进行排序时,如何使用GridViewSortEventArgs传递给事件处理方法的 对象取消排序操作。
<%@ 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当“排序”按钮 (其属性设置为“Sort”的按钮CommandName
时,控件将引发 Sorting 事件) 单击,但在控件处理排序操作之前GridView。 这允许你提供一个事件处理方法,该方法执行自定义例程,例如,每当发生此事件时取消排序操作。
对象 GridViewSortEventArgs 传递给事件处理方法,该方法允许您指定或确定排序表达式和排序方向,以便对控件进行 GridView 排序。 若要确定排序表达式,请使用 SortExpression 属性。 若要确定排序方向,请使用 SortDirection 属性。 还可以通过将 属性设置为 Canceltrue
来取消排序操作。
有关如何处理事件的详细信息,请参阅 处理和引发事件。
有关 实例 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) |