Saturday, January 15, 2011

Sort datatable in .NET

Sorting a data table before binding to a data control like gridview or datalist is provided by microsoft through it's predefined methods which is defaultview.sort.
Example:
Code:
  //C#  
  dt1.DefaultView.Sort = "Name Desc";  
  //VB.NET  
  dt1.DefaultView.Sort = "Name Desc" 
Where dt1 is your datatable. Or you could create a dataview object as provided by MSDN.
Source: MSDN

0 comments:

Post a Comment