We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to load pages in OnDemand using async await?

SfDataPager allows you to load the data for the current page, in OnDemandPaging, at runtime. You can enable OnDemandPaging by setting SfDataPager.UseOnDemandPaging to True. The data for the current page needs to be loaded in SfDataPager.OnDemandLoading event via SfDataPager.LoadDynamicItems method. When using OnDemandPaging, you may have to read data from some external server sometimes, it takes some time to read the data. In this case, you can delay the loading in SfDataPager.OnDemandLoading event by using async and await.

The following section shows you how to load the data with some delay in OnDemandPaging using async and await.

Here, SfDataPager and SfDataGrid are defined and SfDataGrid.ItemsSource is bound to SfDataPager.PagedSource. Also OnDemandLoading event is hooked for SfDataPager.

XAML

 

The OnDemandLoading event is triggered when the pager moves to the corresponding page. The OnDemandLoading event contains the following event arguments:

  • StartIndex: Corresponding page start index.
  • PageSize: Number of items to be loaded for that page.

Here dataPager_OnDemandLoading is defined with async keyword to await data loading. Inside dataPager_OnDemandLoading, GetEmployeesDetailsListAync method is called with await keyword and the execution is stopped here until GetEmployeesDetailsListAync returns the data. GetEmployeesDetailsListAync returns the data for the page with some delay.

Note: Here data is returned with some delay in GetEmployeesDetailsListAync method using Thread.Sleep method.

C#

Note: The above code shows build error in WinRT platform as the Thread.Sleep method is not supported in WinRT. Use Task.Delay to delay the data loading in WinRT as shown in the following code snippet.

WinRT and UWP code

Sample Links:

WPF

WRT

Silverlight

UWP

 

Article ID: Published Date: Last Revised Date: Platform: Control: .NET Framework:
2827 11/21/2014 01/25/2016 WinRT SfDataGrid 4.5
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.