[知识点]datatable排序、取部分数据、截取某字段的长度

1、  

      /// <summary>
        /// datatable排序、取部分数据、截取某字段的长度
        /// </summary>
        /// <param name="dt">datatable</param>
        /// <param name="sortStr">排序条件</param>
        /// <param name="statrNums">数据开始位置</param>
        /// <param name="nums">数据条数</param>
        /// <returns></returns>  

      public DataTable dataTableSort(DataTable dt, string sortStr, Int32 statrNums, Int32 nums)
        {

            DataView dv = dt.DefaultView;
            dv.Sort = sortStr + " desc";

            DataTable dts = dt.Clone();
            string sfilename = string.Empty;
            Int32 lengthNum = 10;

            for (int j = statrNums; j < dv.Count && j < nums; j++)
            {
                DataRow row1 = dv[j].Row;
                sfilename = row1["filename"].ToString();
                if (sfilename.Length >= lengthNum)
                {
                    sfilename = sfilename.Substring(0, lengthNum) + "...";
                }
                row1["filename"] = sfilename;
                dts.ImportRow(row1);
            }
            return dts;
        }

 

2、

posted @ 2009-05-08 09:46  龙卷风清扬  阅读(1202)  评论(0编辑  收藏  举报