private string ResetSortToColumn(string sSortField)
        {
            if (SortField.Length < 1)
            {
                SortField = sSortField;
                SortDir   = string.Empty;
            }
            else
            {
                if (SortField.ToLowerInvariant() != sSortField.ToLowerInvariant())
                {
                    SortDir = string.Empty;                      //previous sort not the same field, force ASC
                }
                SortField = sSortField;
            }

            if (SortDir.Trim().ToUpperInvariant().IndexOf("ASC") < 0)
            {
                SortDir = "ASC";
            }
            else
            {
                SortDir = "DESC";
            }
            sSortField = SortField + "   " + SortDir;
            return(sSortField);
        }
Esempio n. 2
0
        public List <T> SortDataList <T>(List <T> d)
        {
            List <T>        query         = null;
            IEnumerable <T> myEnumerables = d.AsEnumerable();

            if (SortDir.Trim().IndexOf("ASC") < 0)
            {
                query = (from enu in myEnumerables
                         orderby GetPropertyValue(enu, SortField) descending
                         select enu).ToList <T>();
            }
            else
            {
                query = (from enu in myEnumerables
                         orderby GetPropertyValue(enu, SortField) ascending
                         select enu).ToList <T>();
            }

            return(query.ToList <T>());
        }