DataView.Sort Property
This page is specific to:.NET Framework Version:1.12.03.03.54.0
.NET Framework Class Library
DataView.Sort Property

Gets or sets the sort column or columns, and sort order for the DataView.

[Visual Basic]
Public Property Sort As String
[C#]
public string Sort {get; set;}
[C++]
public: __property String* get_Sort();
public: __property void set_Sort(String*);
[JScript]
public function get Sort() : String;
public function set Sort(String);

Property Value

A string containing the column name followed by "ASC" (ascending) or "DESC" (descending). Columns are sorted ascending by default. Multiple columns can be separated by commas.

Remarks

For more information, see Creating and Using DataViews.

Example

[Visual Basic, C#, C++] The following example instructs the DataView to sort the table by two columns.

[Visual Basic] 
Private Sub SortByTwoColumns()
   ' Get the DefaultViewManager of a DataTable.
   Dim myDataView As DataView
   myDataView = DataTable1.DefaultView
   ' By default, the first column sorted ascending.
   myDataView.Sort = "State, ZipCode DESC"
End Sub

[C#] 
private void SortByTwoColumns()
{
   // Get the DefaultViewManager of a DataTable.
   DataView myDataView = DataTable1.DefaultView;
   // By default, the first column sorted ascending.
   myDataView.Sort = "State, ZipCode DESC";
}

[C++] 
private:
 void SortByTwoColumns()
 {
    // Get the DefaultViewManager of a DataTable.
    DataView* myDataView = DataTable1->DefaultView;
    // By default, the first column sorted ascending.
    myDataView->Sort = S"State, ZipCode DESC";
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataView Class | DataView Members | System.Data Namespace | RowFilter | Expression

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View