Issues with sorting a dynamically created Gridview
-
I am working on a project and I am a bit stumped with sorting of a Gridview. I am creating a DataTable, and one of the columns is populated with decimal numbers ranging from -100.00 to +100.00. I then DataBind the DataTable to the GridView, and then sort on the column. The problem is its sorting it as text, not as decimal numbers - so its sorted something like this: 9.33, -7.6, 3.3, 2.02, 14.6, -1.8, -1, 0.99, etc which isn't at all what I want! How can I make the GridView realise the data is decimal, not text, and sort correctly. I am almost at the point where I might just insert the numbers back into SQL as decimal, and then read it back in sorted! Thanks
-
I am working on a project and I am a bit stumped with sorting of a Gridview. I am creating a DataTable, and one of the columns is populated with decimal numbers ranging from -100.00 to +100.00. I then DataBind the DataTable to the GridView, and then sort on the column. The problem is its sorting it as text, not as decimal numbers - so its sorted something like this: 9.33, -7.6, 3.3, 2.02, 14.6, -1.8, -1, 0.99, etc which isn't at all what I want! How can I make the GridView realise the data is decimal, not text, and sort correctly. I am almost at the point where I might just insert the numbers back into SQL as decimal, and then read it back in sorted! Thanks
Do you have all column type specified for your data table ? If yes, take a
DataView
from it and use sort functions on theDataView
and bindDataView
to the grid.All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
Do you have all column type specified for your data table ? If yes, take a
DataView
from it and use sort functions on theDataView
and bindDataView
to the grid.All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
Thank you, that has worked! (
dt.Columns.Add("_SortColumn_").DataType = System.Type.GetType("System.Decimal")
)Glad to know it helped
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions