SessionIDs ids = (SessionIDs)Session["IDs"];
BSDataContext ct = new BSDataContext();
var customers = from cust in ct.tblCustomers
where cust.AccountID == ids.accountID
join mem in ct.tblCustomerMemberships on cust.CustomerID equals mem.CustomerID
orderby drpFilter.SelectedValue descending
select new { cust.CustomerID, cust.Mobile, cust.BusinessPhone, cust.Code, cust.Email, cust.HomePhone, mem.Membership, Name = cust.FirstName + cust.LastName };
grdCustomer.DataSource = customers;
grdCustomer.DataBind();
仍然无法执行排序。
如果我写cust.Code
而不是drp.selectedvalue
排序就完成了!为什么?
您必须检查if
用户要在哪一列上进行排序并相应地对其进行排序的条件:
var customers = from cust in ct.tblCustomers
where cust.AccountID == ids.accountID
join mem in ct.tblCustomerMemberships
on cust.CustomerID equals mem.CustomerID
select new
{ cust.CustomerID,
cust.Mobile,
cust.BusinessPhone,
cust.Code,
cust.Email,
cust.HomePhone,
mem.Membership,
Name = cust.FirstName + cust.LastName
};
if(drpFilter.SelectedValue == "Code")
customers = customers.OrderByDescending(x=>x.Code);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句