简体   繁体   中英

Sorting an asp.net drop down list in descending order

I am sorting my incoming files by my 'Submitted' column (which is a date/time stamp field), however I need it to be in descending order with the most recent file on top. From my research, it looked like I would simply do this: view.Sort = "Submitted desc";

Is there something I'm missing? Here's the entire method:

private void PopulatePendingQueryGridView()
{
    DataTable dt = new DataTable();
    DataColumn col1 = new DataColumn("Spreadsheet", typeof(string));
    dt.Columns.Add(col1);
    DataColumn col2 = new DataColumn("Submitted", typeof(string));
    dt.Columns.Add(col2);
    string folder = Path.Combine(config.BulkQueryUploadFolder, CurrentUser);
    if (Directory.Exists(folder))
    {
        string[] qryFiles = Directory.GetFiles(folder, "*.xlsx");
        foreach (string qryFile in qryFiles)
        {
            FileInfo info = new FileInfo(qryFile);
            DataRow row = dt.NewRow();
            row["Spreadsheet"] = info.Name;
            row["Submitted"] = info.CreationTime.ToString("yyyy/MM/dd HH:mm:ss");
            dt.Rows.Add(row);
        }
    }
    DataView view = new DataView(dt);
    view.Sort = "Submitted desc";
    pendingQryGridView.DataSource = view;
    pendingQryGridView.DataBind();
    gridUpdatePanel.Update();
}

Change your Submitted column data type to datetime. the sort direction shouldn't be case sensitive, but I'm not sure.

If needed you can set your datagrid field with a specified format.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM