0
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();

Still sorting is not performing.

If I write cust.Code instead of drp.selectedvalue then sorting is done! Why?

1
  • I suggest you wrap all this in an ObjectDataSource or if you are using Web Forms 4.5 jump directly into model binders and binding to IQueryable Commented Nov 18, 2014 at 10:33

1 Answer 1

1

You have to check with if condition that user wants to sort on what column and sort it accordingly:

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);
Sign up to request clarification or add additional context in comments.

4 Comments

Still not performing :(
what is the selectedValue coming? it is just for example that you have to check selectedValue and sort on property user is asking accordingly
i am using debugging to check the whether if function is true or not. Its true and orderby function is also performed but still sorting is not showing...
you have to reassign customers as it returns new list like customers = customers.OrderByDescending(x=>x.Code)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.