日期:2014-05-20 浏览次数:20941 次
{ if (!IsPostBack) { IsLogin(); ViewState["SortOrder"] = "ContactNum"; ViewState["OrderDire"] = "ascending"; GvDataBind(); } } private void GvDataBind() { int year = Convert.ToInt32(Request.QueryString["ddlYear"]); var contracts = from c in db.B_Contract_Out join h in db.B_Hospital on c.HospitalID equals h.ID into ch where c.C4 == "1" from chs in ch.DefaultIfEmpty() join u in db.sys_User on c.PrincipalUser equals u.UserID into cu from cus in cu.DefaultIfEmpty() join p in db.B_PayRecord on c.ID equals p.ContractID into cp from cps in cp.DefaultIfEmpty() where c.AllMoney != Convert.ToDouble(cps.PayMoney) where c.CreateTime.Value.Year == year where c.ContractType == type orderby c.ContractDate descending orderby "c." + ViewState["SortOrder"] + " " + ViewState["OrderDire"] select new { payMoney = GetPayedMoney(c.ID), ArmNames = GetArmariumName(c.ID), .... cus.U_CName, qiankuan = GetQianKuan(Convert.ToDouble(c.AllMoney), c.ID) }; var cons = contracts.ToList().Where(c => GetQianKuan(Convert.ToDouble(c.AllMoney), c.ID) != 0); //去除重复项 var con = cons.Distinct(); GvContract.DataSource = con; GvContract.DataBind(); protected void GvContract_Sorting(object sender, GridViewSortEventArgs e) { string sPage = e.SortExpression; if (ViewState["SortOrder"].ToString() == sPage) { if (ViewState["OrderDire"].ToString() == "descending") ViewState["OrderDire"] = "ascending"; else ViewState["OrderDire"] = "descending"; } else { ViewState["SortOrder"] = e.SortExpression; } GvDataBind(); }
orderby c.ContractDate descending ,GetPropertyValue(c,ViewState["SortOrder"].ToString()) ascending,GetPropertyValue(c,ViewState["OrderDire"].ToString()) ascending private static object GetPropertyValue(object obj, string property) { System.Reflection.PropertyInfo propertyInfo=obj.GetType().GetProperty(property); return propertyInfo.GetValue(obj, null); }
------解决方案--------------------