DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("xmls/tops20.aspx"));
DataView tableview = ds.Tables[0].DefaultView;
tableview.Sort = " marks desc ";
GvList.DataSource = tableview;
GvList.DataBind();
显示效果有点问题,上面积个是对的,下面几个也是对的,放在一起就不对了。
------解决方案--------------------------------------------------------
类似这样:
ds.Tables[0].Columns.Add("iPersonOrderSort",System.Type.GetType("System.Int32"));
ds.Tables[0].Columns["iPersonOrderSort"].Expression = "Convert(iPersonOrder,'System.Int32')";
DataView dv = ds.Tables[0].DefaultView;
dv.Sort = "iPersonOrderSort";
------解决方案--------------------------------------------------------
GvList.DataSource =dt.AsEnumerable().OrderBy(t => Convert.ToInt32(t.Field<string>("marks").Trim())).Select(t => new
{
userid = t.Field<string>("userid"),
marks = t.Field<string>("marks")
……
});
------解决方案--------------------------------------------------------
DataTable dt = new DataTable();
dt.Columns.Add("产品", typeof(int));
ViewState["SortOrder"] = "产品";
ViewState["OrderDire"] = "ASC";
DataTable dt = GetData();//获取DataTable
DataView view = dt.DefaultView;
string sort = (string)ViewState["SortOrder"] + " " + (string)ViewState["OrderDire"];
view.Sort = sort;
GridView1.DataSource = view;
GridView1.DataBind();