Export (0) Print
Expand All

DataControlField.SortExpression Property

Note: This property is new in the .NET Framework version 2.0.

Gets or sets a sort expression that is used by a data source control to sort data.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public virtual string SortExpression { get; set; }
/** @property */
public String get_SortExpression ()

/** @property */
public void set_SortExpression (String value)

public function get SortExpression () : String

public function set SortExpression (value : String)

Property Value

A sort expression that is used by a data source control to sort data. The default value is an empty string ("").

The OnFieldChanged method is called to raise a state change event when the SortExpression property is set.

The value of the SortExpression property is stored in view state.

The following code example demonstrates how to use the SortExpression property to assign a sort expression to a data control field.

<%@ page language="C#" %>
<html>
<body>
  <form 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="VJ#" %>
<html>
<body>
  <form runat="server">

    <asp:sqldatasource
      id="SqlDataSource1"
      runat="server"
      connectionstring="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;"
      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>

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft