Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datetime sort in Dataview

Status
Not open for further replies.

redaccess

MIS
Aug 2, 2001
110
0
0
US
I'm attempting to use the Sort method on a DateTime field within a DataView and it is sorting as a text field instead of a DateTime field when it's displayed in the datagrid.

When sorting the field in SQL Server2K it sorts correctly so I must be losing the DateTime declaration when I fill the datatable or the dataview. My abbreviated code looks like the following:

DataTable dt = ds.Tables[0];
dv = dt.defaultview;
dv.Sort = "EnteredDate desc";
dgTestCases.DataSource = dv;
dgTestCases.DataBind();

Any ideas on how to sort the DataView on the datetime field as a true Date sort?

Thanks.
 
I've fixed the problem. Instead of passing the values as DateTime, I converted them to varchar in the sql statement in the yyyymmddd format and sorted it by that. Then in the datagrid, I simply used the dataformatstring method to display the date correctly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top