Freigeben über


ListViewSortEventArgs.SortDirection Eigenschaft

Definition

Ruft die Richtung ab, in der das ListView-Steuerelement sortiert werden soll, oder legt diese fest.

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

Eigenschaftswert

Einer der SortDirection-Werte.

Beispiele

Im folgenden Beispiel wird gezeigt, wie das ListViewSortEventArgs -Objekt verwendet wird, um die Sortierrichtung und die zu sortierende Spalte anzuzeigen. Dieses Codebeispiel ist Teil eines größeren Beispiels, das für die ListViewSortEventArgs-Klasse bereitgestellt wird.

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

Hinweise

Wenn das Sorting Ereignis ausgelöst wird, können Sie die SortDirection -Eigenschaft verwenden, um die Reihenfolge anzugeben oder zu bestimmen, in der das ListView Steuerelement Elemente sortiert.

Gilt für:

Weitere Informationen