30 April 2014

How to Sort a DataTable given column and direction in c#.net

public static DataTable resort(DataTable dt_input, string colName, string direction)  //direction means "ASC" or "DESC"
        {
            DataTable dt_output = null;
            dt_input.DefaultView.Sort = colName + " " + direction;
            dt_output = dt_input.DefaultView.ToTable();
            return dt_output;
        }