共用方式為


SortDirection 列舉

定義

指定項目清單的排序方向。

public enum class SortDirection
public enum SortDirection
type SortDirection = 
Public Enum SortDirection
繼承
SortDirection

欄位

Ascending 0

由小到大排序。 例如,從 A 到 Z。

Descending 1

由大到小排序。 例如,從 Z 到 A。

範例

下列程式碼範例示範如何使用 SortDirection 列舉來判斷控制項顯示其專案的方向 GridView 。 控制項 SortDirectionGridView 屬性會針對其值進行測試,以判斷排序方向。


<%@ 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 AuthorsGridView_Sorted(Object sender, EventArgs e)
  {
      
    // Display the sort direction.   
    if(AuthorsGridView.SortDirection == SortDirection.Ascending)
    {  
      Message.Text = "Sorting in ascending order.";
    }
    else
    {
      Message.Text = "Sorting in descending order.";
    }
        
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>SortDirection Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>SortDirection Example</h3>
            
      <asp:label id="Message"
        forecolor="Red"
        runat="server"/>
        
      <br/><br/>    
          
      <asp:gridview id="AuthorsGridView"
        datasourceid="AuthorsSqlDataSource"
        allowsorting="true"
        onsorted="AuthorsGridView_Sorted"  
        runat="server"/>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Pubs sample database.                        -->
      <asp:sqldatasource id="AuthorsSqlDataSource"  
        selectcommand="SELECT [au_id], [au_lname], [au_fname], [address], [city], [state], [zip], [contract] FROM [authors]"
        updatecommand="UPDATE authors SET au_lname=@au_lname, au_fname=@au_fname, address=@address, city=@city, state=@state, zip=@zip, contract=@contract WHERE (authors.au_id = @au_id)"
        connectionstring="server=localhost;database=pubs;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </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 AuthorsGridView_Sorted(ByVal sender As Object, ByVal e As EventArgs)
      
    ' Display the sort direction.   
    If AuthorsGridView.SortDirection = SortDirection.Ascending Then
 
      Message.Text = "Sorting in ascending order."
    
    Else
    
      Message.Text = "Sorting in descending order."
    
    End If
        
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>SortDirection Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>SortDirection Example</h3>
            
      <asp:label id="Message"
        forecolor="Red"
        runat="server"/>
        
      <br/><br/>    
          
      <asp:gridview id="AuthorsGridView"
        datasourceid="AuthorsSqlDataSource"
        allowsorting="true"
        onsorted="AuthorsGridView_Sorted"  
        runat="server"/>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Pubs sample database.                        -->
      <asp:sqldatasource id="AuthorsSqlDataSource"  
        selectcommand="SELECT [au_id], [au_lname], [au_fname], [address], [city], [state], [zip], [contract] FROM [authors]"
        updatecommand="UPDATE authors SET au_lname=@au_lname, au_fname=@au_fname, address=@address, city=@city, state=@state, zip=@zip, contract=@contract WHERE (authors.au_id = @au_id)"
        connectionstring="server=localhost;database=pubs;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

備註

列舉 SortDirection 是用來表示排序專案的方向。 屬性通常會使用屬性 (,例如 SortDirection 類別的 GridView 屬性) ,以指出控制項中顯示專案的順序。

適用於

另請參閱