The idea behind writing this article is to overcome the problem related to sorting of collection having null values in it. Recently I was working with GridView control and I was using generic collection list as a data source to it. While resolving this problem alone I developed a good piece of functionality which I do feel will help most of you in your development activity.
The feature incorporated in the GridView are as follows:
I had nullable value field data type in my database table. So I used nullable datatype of C# in my asp.net code. Doing so I encountered sorting failure problem with IComparer. After some research and development I came up with the solution. I used GetValueOrDefault() to resolve this. How I applied this to my solution is demonstrated below.Consider Database table schema as:
Implement IComparer:Business Entity Class Country
In below class we have three field as discussed. In this we have m_CountryTradeCode as nullable data type. I was facing problem sorting nullable data type. So I got a workaround for this as shown here.