views:

36

answers:

1

Editing some legacy code that populates a datagrid entirely in code. I need to order it by two columns but I don't know how. Which event do I hook into and what can I do to order the 2nd and 3rd columns (that contain dates) in order of most recent first?

Edit: Argh it's a datagrid

+1  A: 

Datagrid or GridView?

you can create a dataview and sort it (in the constuctor) then bind this back to the grid in the "sorting" event

something like this might be what you're after

protected void myGridView_Sorting(object sender, GridViewSortEventArgs e)
    {
        // Your data
        DataTable dt = new DataTable();

        // Create the view
        DataView dv = new DataView(dt, "", "COLUMN_TO_SORT", DataViewRowState.CurrentRows);

        // Rebind
        myGridView.DataSource = dt;
        myGridView.DataBind();
    }
Matt Joslin