SortDirection 枚举

定义

指定对项列表进行排序的方向。

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

字段

Ascending 0

从小到大排序。 例如,从 A 到 Z。

Descending 1

从大到小排序。 例如,从 Z 到 A。

示例

下面的代码示例演示如何使用 SortDirection 枚举来确定控件显示其项的方向 GridView 。 控件 SortDirection 的属性 GridView 已针对其值进行测试,以确定排序方向。


<%@ 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 用于表示项目排序的方向。 属性通常由属性 ((如SortDirectionGridView类的属性) )用来指示在控件中显示项的顺序。

适用于

另请参阅