This is a migrated thread and some comments may be shown as answers.

GridViewDataColumn DataType not sorting correctly

2 Answers 153 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 14 Jun 2013, 05:46 PM
I have a gridview that is built from a collection of records. I set the datatype of each column, and I can confirm that the datatype is correct in the gridview itself (by checking in debug). That being said, when I sort on certain numeric type columns - the grid is treating it as a string. Am I missing some kind of property? Here is my code. 

var columns = mainViewModel.Records.First()
                .Properties
                .Select((x, i) => new { Name = x.Name, DataType = x.DataType, Index = i })
                .ToArray();
 
 
            foreach (var column in columns)
            {
                var binding = new Binding(string.Format("Properties[{0}].Value", column.Index));
 
                GridViewDataColumn col = new GridViewDataColumn();
                 
                col.UniqueName = column.Name;
                col.Header = column.Name;
                col.DataMemberBinding = binding;                                   
                col.DataType = column.DataType;               
                col.IsSortable = true;               
 
                fleetGrid.Columns.Add(col);
            }

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimitrina
Telerik team
answered on 17 Jun 2013, 10:51 AM
Hello,

Would you please share what is the type of the "Properties[{0}].Value" property? If it is string, then the data will be sorted as string no matter what type you specify for the DataType. If it is of type object, then it will be sorted correctly based on the DataType you have set.
 

Regards,
Didie
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Michael
Top achievements
Rank 1
answered on 17 Jun 2013, 02:25 PM
Well that answers that question... The  "Properties[{0}].Value" is a string. I guess I was under the assumption that I could in effect "cast" it into a GridViewDataColumn DataType - guess not. Thanks for the help!
Tags
GridView
Asked by
Michael
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Michael
Top achievements
Rank 1
Share this question
or