DataControlField.SortExpression 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置数据源控件用来对数据进行排序的排序表达式。
public:
virtual property System::String ^ SortExpression { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.TypeConverter("System.Web.UI.Design.DataSourceViewSchemaConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public virtual string SortExpression { get; set; }
[System.ComponentModel.TypeConverter("System.Web.UI.Design.DataSourceViewSchemaConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public virtual string SortExpression { get; set; }
[<System.ComponentModel.TypeConverter("System.Web.UI.Design.DataSourceViewSchemaConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.SortExpression : string with get, set
[<System.ComponentModel.TypeConverter("System.Web.UI.Design.DataSourceViewSchemaConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.SortExpression : string with get, set
Public Overridable Property SortExpression As String
属性值
由数据源控件用来对数据进行排序的排序表达式。 默认值为空字符串 ("")。
- 属性
示例
下面的代码示例演示如何使用 SortExpression 属性向数据控件字段分配排序表达式。
<%@ page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:sqldatasource
id="SqlDataSource1"
runat="server"
connectionstring="<%$ ConnectionStrings:MyNorthwind%>"
selectcommand="Select * From Employees">
</asp:sqldatasource>
<asp:detailsview
id="DetailsView1"
runat="server"
allowpaging="True"
datasourceid="SqlDataSource1"
height="208px"
width="264px"
autogeneraterows="False">
<fields>
<asp:boundfield
sortexpression="LastName"
datafield="LastName"
headertext="LastName">
<itemstyle backcolor="Yellow">
</itemstyle>
</asp:boundfield>
<asp:boundfield
sortexpression="FirstName"
datafield="FirstName"
headertext="FirstName">
<itemstyle forecolor="#C00000">
</itemstyle>
</asp:boundfield>
<asp:buttonfield
text="TestButton"
buttontype="Button">
</asp:buttonfield>
</fields>
</asp:detailsview>
</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">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:sqldatasource
id="SqlDataSource1"
runat="server"
connectionstring="<%$ ConnectionStrings:MyNorthwind%>"
selectcommand="Select * From Employees">
</asp:sqldatasource>
<asp:detailsview
id="DetailsView1"
runat="server"
allowpaging="True"
datasourceid="SqlDataSource1"
height="208px"
width="264px"
autogeneraterows="False">
<fields>
<asp:boundfield
sortexpression="LastName"
datafield="LastName"
headertext="LastName">
<itemstyle backcolor="Yellow">
</itemstyle>
</asp:boundfield>
<asp:boundfield
sortexpression="FirstName"
datafield="FirstName"
headertext="FirstName">
<itemstyle forecolor="#C00000">
</itemstyle>
</asp:boundfield>
<asp:buttonfield
text="TestButton"
buttontype="Button">
</asp:buttonfield>
</fields>
</asp:detailsview>
</form>
</body>
</html>
注解
当 OnFieldChanged 设置属性时 SortExpression ,将调用该方法以引发状态更改事件。
属性的值 SortExpression 存储在视图状态中。