Infragistics Home

Infragistics Forums

Infragistics community online discussions.
Welcome to Infragistics Forums Sign in | FAQ
in Search

Problem with using Paging and Sorting

Last post 07-03-2008 12:59 by kchang. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 06-26-2008 11:37

    • kchang
    • Not Ranked
    • Joined on 06-26-2008
    • Points 70

    Problem with using Paging and Sorting

    Hi everyone,

    In my project, i am using a webgrid to do paging and sorting.  I am doing both of these using Linq.skip().take()

    With sorting, i use the Grid Sortcolumn event handler.  With paging, i'm sending the page number via query string and the code behind will take the page number from the query string and skip records.

    The problem i am facing now is on the initial load, the sortcolumn even handler will work every time i click on a column to be sorted, however, once i go to a new page (query string), whenever i try to click on a sorted column, the sort column event handler will not be called.  I can see the page is getting postback, but still no sort column even handler. 

    Any ideas?

    • Post Points: 20
  • 06-26-2008 15:35 In reply to

    Re: Problem with using Paging and Sorting

    A couple of important questions - what is your datasource, and how are you binding?  Are you using the LinqDataSource, or are you binding to a IQueryable collection?  When do you assign data to the grid control?  The recommended databinding stragety for the WebGrid is to assign a datasource in the grid's InitializeDataSource event.  If you're not connecting your data there, you may want to try and see if that fixes the problem. 

    Hope this helps,

    -Tony

    Anthony Lombardo
    Lead Technical Evangelist
    Infragistics, Inc.
    Worldwide Evangelism Group

    tonyl@infragistics.com
    blogs.infragistics.com

    • Post Points: 20
  • 06-26-2008 16:14 In reply to

    • kchang
    • Not Ranked
    • Joined on 06-26-2008
    • Points 70

    Re: Problem with using Paging and Sorting

    Tony,

    This is an example of how i used linq and databinding.

    var query = from p in db.example select p;

    ExampleGrid.Clear();

    ExampleGrid.DataSource = query.Skip((PageNumber - 1) * NumberOfRowsToDisplay).Take(NumberOfRowsToDisplay).ToList();

    ExampleGrid.DataBind();

    I databind to the grid almost all over the place such as when i'm sorting or paging.  I will try to bind the data in the initalizedatasource event and see if that will work. 

    Thanks!

    • Post Points: 20
  • 07-02-2008 21:24 In reply to

    • cantrellr
    • Not Ranked
    • Joined on 07-01-2008
    • Los Angeles
    • Points 165

    Re: Problem with using Paging and Sorting

    Wanted to find out whether you found a resolution to your problem.  I am having the same challenge.  Not certain it is master page related, but it is the only difference as the same ascx works fine when loaded up in a normal page.

     

    Thanks

    • Post Points: 20
  • 07-03-2008 3:05 In reply to

    Re: Problem with using Paging and Sorting

    Answer

    It really depends on your setup. Here is what I am trying (against Linq To Sql for NorthWind) and it is working perfectly - I guess if you pass the correct page via GET parameter in the query string, it can be used in the InitializeDataSource event of the grid and you can proceed with binding against your Linq datasource

    public partial class _Default : System.Web.UI.Page
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            UltraWebGrid1.InitializeDataSource += new Infragistics.WebUI.UltraWebGrid.InitializeDataSourceEventHandler(UltraWebGrid1_InitializeDataSource);
        }

        void UltraWebGrid1_InitializeDataSource(object sender, Infragistics.WebUI.UltraWebGrid.UltraGridEventArgs e)
        {
            DataClassesDataContext dataContext = new DataClassesDataContext();


            UltraWebGrid1.DataSource = dataContext.Categories.Skip(3).Take(3).ToList();
            UltraWebGrid1.DataBind();     
        }

        protected void Page_Load(object sender, EventArgs e)
        {
           
        }
    }

    Best Regards,
    Rumen Stankov (MCSD.NET)
    The Infragistics ASP.NET Team
    • Post Points: 20
  • 07-03-2008 12:59 In reply to

    • kchang
    • Not Ranked
    • Joined on 06-26-2008
    • Points 70

    Re: Problem with using Paging and Sorting

    Answer

    I fixed my problem, however, i changed the way i did paging.  Before, i paging using links and sending the page number to a query string.  Now, i am using the custom paging function on the grid.  I'm still using Linq so not all the data is loaded to the grid.  In order to do this, i had to use an array that would store the page numbers and then load it into the grid on InitializeLayout event.  So far this is working for me. 

    • Post Points: 5
Page 1 of 1 (6 items)
Powered by Community Server (Commercial Edition), by Telligent Systems