Saturday, March 24, 2012

Sort multiple column of a DataView in Asp.net C#




Please visit my new Web Site https://coderstechzone.com




In many case studies we found that when sorting is required developers done this job in back end means running extra query in database even though he has an already disconnected record set in his hand like DataView which also create an overhead to the application. One can easily sort the DataView columns in both ascending and descending order. Its very simple and for showing or displaying any type of sorted data in your report or details page you can do it without connecting to the Database through disconnected DataView. To define the sort direction we can use ASC or DESC keyword after the column name. For multiple column we just add comma separator for each column.







Code Example is given below:

// Create DataView from a DataTable Instance
DataView DV = datatable1.DefaultView;

// If you do not define sorting order then default Ascending order will be applied
DV.Sort = "ProductName ASC, CategoryName ASC, Price DESC";

For more details on DataTable or DataView CLICK HERE.

0 comments:

Want to say something?
I WOULD BE DELIGHTED TO HEAR FROM YOU

Want To Search More?
Google Search on Internet
Subscribe RSS Subscribe RSS
Article Categories
  • Asp.net
  • Gridview
  • Javascript
  • AJAX
  • Sql server
  • XML
  • CSS
  • Free Web Site Templates
  • Free Desktop Wallpapers
  • TopOfBlogs
     
    Free ASP.NET articles,C#.NET,VB.NET tutorials and Examples,Ajax,SQL Server,Javascript,Jquery,XML,GridView Articles and code examples -- by Shawpnendu Bikash