ListViewSortEventArgs.SortDirection 属性

定义

获取或设置 ListView 控件的排序方向。

public:
 property System::Web::UI::WebControls::SortDirection SortDirection { System::Web::UI::WebControls::SortDirection get(); void set(System::Web::UI::WebControls::SortDirection value); };
public System.Web.UI.WebControls.SortDirection SortDirection { get; set; }
member this.SortDirection : System.Web.UI.WebControls.SortDirection with get, set
Public Property SortDirection As SortDirection

属性值

SortDirection 值之一。

示例

以下示例演示如何使用 ListViewSortEventArgs 对象显示排序方向和正在排序的列。 此代码示例是为 ListViewSortEventArgs 类提供的一个更大示例的一部分。

void ContactsListView_Sorting(Object sender, ListViewSortEventArgs e)
{
  // Check the sort direction to set the image URL accordingly.
  string imgUrl;
  if (e.SortDirection == SortDirection.Ascending)
    imgUrl = "~/images/ascending.gif";
  else
    imgUrl = "~/images/descending.gif";
    
  // Check which field is being sorted
  // to set the visibility of the image controls.
  Image sortImage1 = (Image) ContactsListView.FindControl("SortImage1");
  Image sortImage2 = (Image)ContactsListView.FindControl("SortImage2");
  Image sortImage3 = (Image)ContactsListView.FindControl("SortImage3");
  switch (e.SortExpression)
  {
    case "FirstName":
      sortImage1.Visible = true;
      sortImage1.ImageUrl = imgUrl;
      sortImage2.Visible = false;
      sortImage3.Visible = false;
      break;
    case "LastName":
      sortImage1.Visible = false;
      sortImage2.Visible = true;
      sortImage2.ImageUrl = imgUrl;
      sortImage3.Visible = false;
      break;
    case "EmailAddress":
      sortImage1.Visible = false;
      sortImage2.Visible = false;
      sortImage3.Visible = true;
      sortImage3.ImageUrl = imgUrl;
      break;
  }
}
Sub ContactsListView_Sorting(ByVal sender As Object, ByVal e As ListViewSortEventArgs) 

  ' Check the sort direction to set the image URL accordingly.
  Dim imgUrl As String
  If e.SortDirection = SortDirection.Ascending Then
    imgUrl = "~/images/ascending.gif"
  Else
    imgUrl = "~/images/descending.gif"
  End If
  
  ' Check which field is being sorted
  ' to set the visibility of the image controls.
  Dim sortImage1 As Image = CType(ContactsListView.FindControl("SortImage1"), Image)
  Dim sortImage2 As Image = CType(ContactsListView.FindControl("SortImage2"), Image)
  Dim sortImage3 As Image = CType(ContactsListView.FindControl("SortImage3"), Image)
  
  Select Case e.SortExpression
    Case "FirstName"
      sortImage1.Visible = True
      sortImage1.ImageUrl = imgUrl
      sortImage2.Visible = False
      sortImage3.Visible = False
    Case "LastName"
      sortImage1.Visible = False
      sortImage2.Visible = True
      sortImage2.ImageUrl = imgUrl
      sortImage3.Visible = False
    Case "EmailAddress"
      sortImage1.Visible = False
      sortImage2.Visible = False
      sortImage3.Visible = True
      sortImage3.ImageUrl = imgUrl
  End Select
  
End Sub

注解

Sorting引发 事件时,可以使用 SortDirection 属性指定或确定控件对项进行排序的顺序ListView

适用于

另请参阅