I want to sort a gridview by a datetime-column so I need to change the datatype of that column
I try it with following code but I’m getting the error:
dt.DefaultView.Table.Columns["Meldingsdatum"].DataType = Type.GetType("System.DateTime");
dt.DefaultView.Sort = "Meldingsdatum asc";
gvOutlookMeldingen.DataSource = dt;
gvOutlookMeldingen.DataBind();
The error message tells you everything you need to know here; either (and preferred) make the column a
DateTimeinitially (and importantly: before you load data), or hack around it. By which I mean perhaps add a second column (DateTime), and push the data accross – inefficient and extra work for no good reason.