I have a problem that has been bugging me for quite some time and I'm in desperate need of help due to I am a beginner in .NET.
I am using a GridView to display the query results. However, instead of injecting it directly to the entity/LINQ data source, I manually code the events such as Load, Sorting and Paging. The problem is in the Sorting, I can't keep the ascending/descending state. One of the possible solutions that I can think of is by Caching the state, however, I feel like there is another way that is more neat. Thus, can you guys suggest me any other ideas that suit better?
Thanks a lot in advance!
Below is the code that I use for the sorting. Apparently, e.SortDirection
will always equals to ascending
no matter how many times I have clicked the Column's Header.
switch (e.SortExpression)
{
case "Album":
if (e.SortDirection == SortDirection.Ascending)
_orderedResult = from doc in _result
orderby doc.DocumentAlbum.Name ascending
select doc;
else
_orderedResult = from doc in _result
orderby doc.DocumentAlbum.Name descending
select doc;
break;
case "Category":
if (e.SortDirection == SortDirection.Ascending)
_orderedResult = from doc in _result
orderby doc.DocumentCategory.Name ascending
select doc;
else
_orderedResult = from doc in _result
orderby doc.DocumentCategory.Name descending
select doc;
break;
case "Title":
if (e.SortDirection == SortDirection.Ascending)
_orderedResult = from doc in _result
orderby doc.Title ascending
select doc;
else
_orderedResult = from doc in _result
orderby doc.Title descending
select doc;
break;
case "Description":
if (e.SortDirection == SortDirection.Ascending)
_orderedResult = from doc in _result
orderby doc.Description ascending
select doc;
else
_orderedResult = from doc in _result
orderby doc.Description descending
select doc;
break;
case "DateCreated":
if (e.SortDirection == SortDirection.Ascending)
_orderedResult = from doc in _result
orderby doc.DateCreated ascending
select doc;
else
_orderedResult = from doc in _result
orderby doc.DateCreated descending
select doc;
break;
case "DateUpdated":
if (e.SortDirection == SortDirection.Ascending)
_orderedResult = from doc in _result
orderby doc.DateUpdated ascending
select doc;
else
_orderedResult = from doc in _result
orderby doc.DateUpdated descending
select doc;
break;
}