开发者

How to sort the grid view whose column is listing integers

开发者 https://www.devze.com 2023-02-11 09:28 出处:网络
I am sorting the grid using DataView\'s \"Sort\" property. I am passing sort expression and the order in which the grid is to be sorted(ASC or DESC). But the problem is, since the column on which I am

I am sorting the grid using DataView's "Sort" property. I am passing sort expression and the order in which the grid is to be sorted(ASC or DESC). But the problem is, since the column on which I am sorting the grid is listing the intergers, the sorting is happening as if it is a string. But I need integer sorting rather string sorting on that column.

The grid displays below as ascending order(string sorting) 55 77 8

But I need开发者_运维百科 the columns to be displayed like this(Integer sorting) 8 55 77

What would be the solution .


I tried the below one.

dt.Columns.Add("SOWId", typeof(int));

You need to specify the type of the item template values before binding the data into data table by using 'typeof' keyword.

This solved the problem... :)


In your DataGrid's BoundField column set the DataFormatString to:

DataFormatString="{0:D}"

This will tell that column that all of the cells contains integers and therefore the sorting will work correctly as you require.

See BoundField.DataFormatString Property for a list of properties you can assign the BoundField as.

0

精彩评论

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

关注公众号