ObjectDataSource.SortParameterName 属性
定义
获取或设置业务对象的名称,SelectMethod 参数使用此业务对象指定数据源排序支持的排序表达式。Gets or sets the name of the business object that the SelectMethod parameter used to specify a sort expression for data source sorting support.
public:
property System::String ^ SortParameterName { System::String ^ get(); void set(System::String ^ value); };
public string SortParameterName { get; set; }
member this.SortParameterName : string with get, set
Public Property SortParameterName As String
属性值
方法参数的名称,此方法参数用于指示哪个参数用于排序数据。The name of the method parameter used to indicate the parameter which is used to sort the data. 默认值为一个空字符串。The default is an empty string.
示例
本部分包含两个代码示例。This section contains two code examples. 第一个代码示例演示如何实现支持排序的类型。The first code example demonstrates how to implement a type that supports sorting. 第二个代码示例演示如何实现排序表达式。The second code example demonstrates how to implement a sort expression.
下面的代码示例演示如何实现支持排序的类型。The following code example demonstrates how to implement a type that supports sorting. SelectMethod SortingData 类的具有参数 sortExpression 。The SelectMethod of the SortingData class takes a parameter, sortExpression. 传递给的字符串 SelectMethod 将用于返回的对象的 Sort 属性 DataView SelectMethod 。The string that is passed to SelectMethod is used for the Sort property of the DataView object that is returned by SelectMethod.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace Samples.AspNet.CS
{
public class SortingData
{
public SortingData()
{
}
private static DataTable table;
private DataTable CreateData()
{
table = new DataTable();
table.Columns.Add("Name", typeof(string));
table.Columns.Add("Number", typeof(int));
table.Rows.Add(new object[] { "one", 1 });
table.Rows.Add(new object[] { "two", 2 });
table.Rows.Add(new object[] { "three", 3 });
table.Rows.Add(new object[] { "four", 4 });
return table;
}
public DataView SelectMethod(string sortExpression)
{
table ??= CreateData();
DataView dv = new DataView(table);
dv.Sort = sortExpression;
return dv;
}
}
}
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Namespace Samples.AspNet.VB
Public Class SortingData
Public Sub New()
End Sub
Private Shared table As DataTable
Private Function CreateData() As DataTable
table = New DataTable()
table.Columns.Add("Name", GetType(String))
table.Columns.Add("Number", GetType(Integer))
table.Rows.Add(New Object() {"one", 1})
table.Rows.Add(New Object() {"two", 2})
table.Rows.Add(New Object() {"three", 3})
table.Rows.Add(New Object() {"four", 4})
Return table
End Function
Public Function SelectMethod(ByVal sortExpression As String) As DataView
If table Is Nothing Then
table = CreateData()
End If
Dim dv As New DataView(table)
dv.Sort = sortExpression
Return dv
End Function
End Class
End Namespace
下面的代码示例演示如何实现排序表达式。The following code example demonstrates how to implement a sort expression. 网页中的代码将创建控件的实例 ObjectDataSource 。The code in the Web page creates an instance of the ObjectDataSource control. TypeName属性设置为 SortingData ,并且 SortParameterName 属性设置为 sortExpression 。The TypeName property is set to SortingData and the SortParameterName property is set to sortExpression. AllowSorting控件的属性 GridView 设置为 true 。The AllowSorting property of the GridView control is set to true. 当用户单击 排序 按钮时,会将字段名称 Name 或 Number 传递到 SelectMethod sort 参数中。When the user clicks the Sort button, the field name, Name or Number, is passed to SelectMethod in the sort parameter.
<%--<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS" Assembly="Samples.AspNet.CS" %>
--%><%@ 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">
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1"
runat="server"
DataSourceID="ObjectDataSource1"
AllowSorting="True">
</asp:GridView>
<asp:ObjectDataSource
ID="ObjectDataSource1"
runat="server"
SelectMethod="SelectMethod"
TypeName="Samples.AspNet.CS.SortingData"
SortParameterName="sortExpression">
</asp:ObjectDataSource>
</div>
</form>
</body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB" Assembly="Samples.AspNet.VB" %>
<%@ 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">
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1"
runat="server"
DataSourceID="ObjectDataSource1"
AllowSorting="True">
</asp:GridView>
<asp:ObjectDataSource
ID="ObjectDataSource1"
runat="server"
SelectMethod="SelectMethod"
TypeName="Samples.AspNet.VB.SortingData"
SortParameterName="sortExpression">
</asp:ObjectDataSource>
</div>
</form>
</body>
</html>
注解
SortParameterName属性用于支持数据源排序。The SortParameterName property is used to support data source sorting. 在 SortExpression 对象上设置属性并将其 DataSourceSelectArguments 传递给方法时 Select ,值将 SortParameterName SelectMethod 根据数据的排序方式标识业务对象方法的参数名称。When a SortExpression property is set on the DataSourceSelectArguments object and passed to the Select method, the SortParameterName value identifies the parameter name of the SelectMethod business object method according to which the data is sorted.
如果 ObjectDataSource 与数据绑定控件关联,传递给此参数的值将采用以逗号分隔的字段值的形式,后跟 "ASC" 或 "DESC" 。If the ObjectDataSource is associated with a data-bound control, the values that are passed to this parameter take the form of comma-separated field values followed by "ASC" or "DESC". 例如,升序排序的值将 Name 为 "Name ASC" 。For example, the value for an ascending sort on Name would be "Name ASC".
SortParameterName属性委托给 SortParameterName ObjectDataSourceView 与控件相关联的对象的属性 ObjectDataSource 。The SortParameterName property delegates to the SortParameterName property of the ObjectDataSourceView object that is associated with the ObjectDataSource control.