1

I am getting following error while sorting on my gridview. "The data source does not support server-side data paging." I am not using obejctdatasource and linqdatasource. Every example or solution on stack overflow I found is using obejctdatasource. [like: http://www.devtoolshed.com/content/gridview-objectdatasource-linq-paging-and-sorting]

Below is my code. How can I fix sorting error in my code? Can I fix it without using objectdatasource.


public List<SearchLoanViewItem> GetSearchresult(EmpowerEntities empower)
        {
            var searchresult = (from m in dbo.MTGTERMS
                                join p in dbo.PROPINFOes
                                    on m.LNKEY equals p.LNKEY
                                join b in dbo.BORRINFOes
                                    on m.LNKEY equals b.LNKEY
                                join d in dbo.DBLOCKS
                                    on m.LNKEY equals d.LNKEY
                                join u in dbo.UCODES3
                                    on m.LNKEY equals u.LNKEY
                                join c in dbo.CODES
                                    on m.LNKEY equals c.LNKEY
                                where b.WHICHBORR == 1
                                      && (c.APPSTATS == null ? "" : c.APPSTATS) != "DEL"
                                select new SearchLoanViewItem
                                           {
                                               lnkey = m.LNKEY,
                                               prop_addr = p.PROP_ADDR,
                                               networklocked = d.NETWORKLOCKED == "Y" ? "Yes" : "No",
                                               username = (d.USERNAME ?? ""),
                                               mailbox = d.MAILBOX,
                                               borr_name = b.BORR_NAME,
                                               ssn = b.BORR_SSN,
                                               phone = b.BORR_PHONE,
                                               employee_loan = (u.CODE67N ?? -1)
                                           }).Take(5).ToList();
            return searchresult;
        }


        public void ShowSearchResults()
        {
            try
            {
                var empower = new EmpowerEntities();
                var searchresult = GetSearchresult(empower);                

                gdvSearchResult.DataSource = searchresult;
                gdvSearchResult.DataBind();
            }
            catch (Exception ex)
            {
                Logger.log("ucSearchLoan", ex.Message, Logger.ERROR);
            }
        }


 protected void Paging_gdvSearchResult(object source, GridViewPageEventArgs e)
        {  
            gdvSearchResult.PageIndex = e.NewPageIndex;
            ShowSearchResults();
        }

protected void gdvSearchResult_SortCommand(object source, GridViewSortEventArgs e)
        {
            try
            {
                var empower = new EmpowerEntities();
                var searchresult = GetSearchresult(empower);

                if (SearchSortType == Constants.ASC)
                    SearchSortType = Constants.DESC;
                else
                    SearchSortType = Constants.ASC;

                SeachSortField = e.SortExpression.ToString();

                if (SeachSortField.Equals(Constants.ASC))
                    gdvSearchResult.DataSource = searchresult.AsEnumerable().OrderBy(a => a.GetType().GetProperty(SeachSortField).GetValue(a, null));
                else
                    gdvSearchResult.DataSource = searchresult.AsEnumerable().OrderByDescending(a => a.GetType().GetProperty(SeachSortField).GetValue(a, null));

                gdvSearchResult.DataBind();        

            }

and my gridview looks like below.

    <asp:GridView runat="server" ID="gdvSearchResult" 
             AutoGenerateColumns="false" OnRowCommand="gdvSearchResult_RowCommand" OnRowCreated="gdvSearchResult_RowCreated" PageSize="2" AllowPaging="true"      AllowSorting="true" OnPageIndexChanging="Paging_gdvSearchResult" OnSorting="gdvSearchResult_SortCommand">
2
  • is it a sorting issue or paging issue ? because your title says that you cannot sort but than the error indicate that it is about paging Commented Jul 11, 2012 at 18:44
  • I see this error while sorting. Paging works fine. Commented Jul 13, 2012 at 22:40

1 Answer 1

1

Issue was fixed when I added casting [Cast<object>().ToList() part]

 if (SeachSortField.Equals(Constants.ASC))
                    gdvSearchResult.DataSource = searchresult.AsEnumerable().OrderBy(a => a.GetType().GetProperty(SeachSortField).GetValue(a, null)).Cast<object>().ToList();
                else
                    gdvSearchResult.DataSource = searchresult.AsEnumerable().OrderByDescending(a => a.GetType().GetProperty(SeachSortField).GetValue(a, null)).Cast<object>().ToList();
Sign up to request clarification or add additional context in comments.

Comments

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.