Condividi tramite


ListViewSortEventArgs.SortDirection Proprietà

Definizione

Ottiene o imposta la direzione in cui ordinare il controllo 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

Valore della proprietà

Uno dei valori di SortDirection.

Esempio

Nell'esempio seguente viene illustrato come usare l'oggetto ListViewSortEventArgs per visualizzare la direzione di ordinamento e la colonna in ordinamento. Questo esempio di codice fa parte di un esempio più grande fornito per la ListViewSortEventArgs classe.

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

Commenti

Quando viene generato l'evento Sorting , è possibile usare la SortDirection proprietà per specificare o determinare l'ordine in cui il ListView controllo ordina gli elementi.

Si applica a

Vedi anche