This is a migrated thread and some comments may be shown as answers.

Custom Sorting of GridView with DataPager

4 Answers 116 Views
DataPager
This is a migrated thread and some comments may be shown as answers.
gureumi
Top achievements
Rank 1
gureumi asked on 03 Feb 2011, 03:50 PM

private
void gridView_Sorting(object sender, GridViewSortingEventArgs e)
 {
    try
    {
       if (schedules == null)
       {
          e.Cancel = true;
          return;
       }
 
 
       if (e.OldSortingState == SortingState.Ascending)
       {
          e.NewSortingState = SortingState.Descending;
          schedules = schedules.OrderByDescending(s => s.Role).ThenBy(s => s.Name).ToList();
       }
       else if (e.OldSortingState == SortingState.Descending)
       {
          schedules = schedules.OrderByDescending(s => s.Name).ToList();
          e.NewSortingState = SortingState.None;
       }
       else
       {
          e.NewSortingState = SortingState.Ascending;
          schedules = schedules.OrderBy(s => s.Role).ThenBy(s => s.Name).ToList();
       }
       this.radDataPager.Source = schedules;
       //e.DataControl.ItemsSource = this.radDataPager.Source;  // replaced by the next line which is the same thing.
       this.gridView.ItemsSource = this.radDataPager.Source;
       this.gridView.Items.Refresh();
 
       this.radDataPager.PageIndex = 0;
       e.Cancel = true;
    }
    catch (Exception ex)
    {
       txtStatus.Text = "Erorr in gridView_Sorting:"+ex.Message;
    }
 }
Custom Sorting (routine shown above) of GridView with DataPager does not seem to work.
It shows sorted items on the current page but it does not navigate to another page.

Can you provide small sample code that works?

Thanks.

4 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 07 Feb 2011, 12:01 PM
Hi gureumi,

We could not quite understand the exact goal that you are after. What page should it navigate to?

We see that you are explicitly making the pager go to the first page by doing this:

this.radDataPager.PageIndex = 0;

Do you mean that it does not go to the first page? Could you please elaborate?

Thanks in advance.

Kind regards,
Ross
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
gureumi
Top achievements
Rank 1
answered on 07 Feb 2011, 03:02 PM
I tried that already.

Simple symptom is it does not move to the next page or any other page.
0
Veselin Vasilev
Telerik team
answered on 07 Feb 2011, 04:37 PM
Hi gureumi,

Have you tried binding the gridview to the PagedSource property of RadDataPager?

Best wishes,
Veselin Vasilev
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
gureumi
Top achievements
Rank 1
answered on 07 Feb 2011, 04:52 PM
Thanks.

You found the problem.

In the Loaded routine 

I had the following.
            this.radDataPager.Source = schedules;
            this.gridView.ItemsSource = this.radDataPager.PagedSource;
            this.gridView.Items.Refresh();


            this.radDataPager.PageIndex = 0;

But the code shown above had this.radDataPager.Source instead of PagedSource.

My stupid mistake. Thanks again...
Tags
DataPager
Asked by
gureumi
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
gureumi
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or