I’m writing my own gridview control. The problem is sorting. What is best practic to do that.
I can write function like that:
public object GetDataForGrid(int currentPage, int rowsPerPage, string sortColumnName, string sortDirection)
{
if(sortColumnName="Date" && sortDirection=="ASC")
{
return Detalizations.OrderBy(x => x.Date).Skip(currentPage*rowsPerPage).ToList();
}
.....
//And over 9000 other branches
}
But ofcourse these solution is not optimal and looks oververbose. But how i can do it right?
Maybe reflection could help me?
what don’t you use the GridView.Sort Method which is made for that scope
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sort.aspx
have also a look at:
http://dotnetslackers.com/articles/gridview/Custom-GridView-with-Paging-and-Filtering.aspx#Custom_Filtering
another simple example
https://web.archive.org/web/20210323170551/http://www.4guysfromrolla.com/articles/012308-1.aspx