日期:2014-05-17 浏览次数:20544 次
DataTable dt = new DataTable(); dt.Columns.Add("UserId", typeof(string)); dt.Columns.Add("UserName", typeof(string)); for (int i = 0; i < 10; i++) { dt.Rows.Add(i.ToString(), i.ToString()); } Response.Write("==========修改前=========<br/>"); foreach (DataRow dr in dt.Rows) { Response.Write(string.Format("用户ID:{0}---用户名称:{1}<br/>", dr["UserId"], dr["UserName"])); } dt = dt.AsEnumerable().OrderByDescending(o => o.Field<string>("UserId")).CopyToDataTable(); Response.Write("==========修改后========="); foreach (DataRow dr in dt.Rows) { Response.Write(string.Format("用户ID:{0}---用户名称:{1}<br/>", dr["UserId"], dr["UserName"])); }