Este artigo foi traduzido por máquina. Para visualizar o arquivo em inglês, marque a caixa de seleção Inglês. Você também pode exibir o texto Em inglês em uma janela pop-up, movendo o ponteiro do mouse sobre o texto.
Tradução
Inglês

Propriedade GridView.SortDirection

 

Obtém a direção de classificação da coluna sendo classificada.

Namespace:   System.Web.UI.WebControls
Assembly:  System.Web (em System.Web.dll)

[BrowsableAttribute(false)]
[PersistenceModeAttribute(PersistenceMode.InnerProperty)]
public virtual SortDirection SortDirection { get; }

Valor da Propriedade

Type: System.Web.UI.WebControls.SortDirection

Um dos valores de SortDirection. O padrão é SortDirection.Ascending.

Use the P:System.Web.UI.WebControls.GridView.SortDirection property to determine whether the column being sorted is sorted in ascending or descending order.

System_CAPS_noteObservação

The T:System.Web.UI.WebControls.GridView control has a built-in sorting feature that automatically sets this property. This property is typically used only when you need to programmatically determine the sort direction or when you are adding your own custom sorting functionality to a T:System.Web.UI.WebControls.GridView control.

The following example demonstrates how to use the P:System.Web.UI.WebControls.GridView.SortDirection property to programmatically determine the sort direction of a T:System.Web.UI.WebControls.GridView control.


<%@ 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_DataBound(Object sender, EventArgs e)
  {

    // Get the header row.
    GridViewRow headerRow = CustomersGridView.HeaderRow;   

    // Get the footer row.
    GridViewRow footerRow = CustomersGridView.FooterRow; 

    // Set the font color of the header and footer rows
    // based on the sort direction. 
    switch (CustomersGridView.SortDirection)
    {
      case SortDirection.Ascending:
        headerRow.ForeColor = System.Drawing.Color.Green;
        footerRow.ForeColor = System.Drawing.Color.Green;
        break;
      case SortDirection.Descending:
        headerRow.ForeColor = System.Drawing.Color.Red;
        footerRow.ForeColor = System.Drawing.Color.Red;
        break;
      default:
        headerRow.ForeColor = System.Drawing.Color.Black;
        footerRow.ForeColor = System.Drawing.Color.Black;
        break;
    }

    // Display the sort order in the footer row.
    footerRow.Cells[0].Text = "Sort Order = " + CustomersGridView.SortDirection.ToString();

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>GridView HeaderRow and FooterRow Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>GridView HeaderRow and FooterRow Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSource" 
        autogeneratecolumns="true"
        emptydatatext="No data available." 
        allowsorting="true"
        allowpaging="true" 
        showheader="true"
        showfooter="true"
        ondatabound="CustomersGridView_DataBound"    
        runat="server">

        <headerstyle backcolor="LightCyan"
          forecolor="MediumBlue"/>

        <footerstyle backcolor="LightCyan"
          forecolor="MediumBlue"/>

      </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>

.NET Framework
Disponível desde 2.0
Retornar ao início
Mostrar: