I have 4 columns in the web grid. In first column, i have date values. i want to sort the data based on this date column. can any body help in this regard?
The data was a string and the grid was behaving correctly.
I was using XML to bind to the grid, and thus, everything is a string. We have an attribute on the XML node that tells us what type of data it is so I used that to force the grid to cast the string to a datetime:
//force the datatype to datetime so the grid can sort correctlyUltraWebGrid1.Columns[i].DataType = "System.DateTime";//format the datetime to a short date stringUltraWebGrid1.Columns[i].Format = "d";
Any answer on this? We are having the same issue - dates are sorted as strings so it ends up being like this (ascending):
On a simple grid (1 level), this works. You can actually going into the designer and set the sort feature (under Features Picker). You can even sort on client or server.
The problem that I have is that I have a hierarchical grid with 2 bands. My date column is in the first band, but I can never get it to sort correctly. It was as if the grid sees that column as a String type and sort it like a string. I've tried setting the format as system.datetime; I've forced the dataset to be of getype(DateTime); I've even updated my sql prior to populating the dataset to use Cast() on that field to datetime. Sorting is still incorrect. What am I missing here? Seems to be a bug.
a) click on the column header
b) something like this in your code-behind, after the grid is bound:
MyWebGrid.Bands(0).SortedColumns.Add(MyWebGrid.Columns.FromKey("MyColumnName"), True)