开发者

Custom data sorting in ASP.NET GridView

Is there a way I can do some custom data sorting in GridView ? I mean for example there is a great in which there are several project ent开发者_运维百科ries, each project has a status like Hold, Complete, Awaiting Feedback, Working and so on... now I would like to sort according to status column but not alphabetically instead I would like to arrange them in custom fashion like Hold then Awaiting Feedback then Working and then complete. Is it possible somehow, if so please provide an example so I can understand.

There is one idea that comes in my mind, that I should create a numeric column in table that contains statuses and assign numbers like 1,2 and 3... in order I like to have and then bind that column in grid, keep it invisible and sort according to it but if there is another simpler way in which I dont have to modify database table I would like to try that first.

Thanks.


I used my own idea and implemented a hidden column named as priority and assigned it numeric values in order, for example since "Hold" has highest priority then it should get numeric value of 1 after that Awaiting Feedback should get 2 and so on... Instead of binding that column with gridview and keeping it hidden I used ORDER BY in sql data source.


Assign a numeric value to each of your possible Status (Hold = 1, Awaiting = 2, etc) and use that numeric value as the Sort Expression property of the GridView column.

Hope this helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜