Custom VirtualLoad is one of VirtualLoad features which allow developer to setup a grid with their own implementation and logic for fetching the data. Note that sorting, editing and all other data-aware functionalities can work in this mode, except Grouping since that Grouping requires all rows to be loaded.
In this topic, you will learn how to implement the custom virtual load in WebGrid.
To Implement custom Virtual Load in WebGrid
- Set the PagingMode to VirtualLoad.
- Set the VirtualLoadMode to Custom.
- Drag ISDataSource control from toolbox to the designer surface.
- Configure Data Source for the newly created ISDataSource.
- Select DataSet for the SchemaType.
- Click Schema Name dropdown and select dsNorthWind from the list.
- In the next dialog, click AutoGenerate button which is located at the most bottom. Click Finish.
- Drag WebGrid control from toolbox to the designer surface.
- Set the DataSourceID to ISDataSource1.
- In the Connect to DataSource dialog, select Orders table as root table and select Retrieve Structure, then click OK.
- Right click on ISDataSource1 and launch the designer, set the Orders table's SelectCount property to GetCount.
- For the WebGrid, set the PagingMode to VirtualLoad and VirtualLoadMode to Custom.
- Write codes that handle virtual load and the total row count in App_Code. For reference, see the codes in App_Code\dsNorthwind_Extended.cs.
- Run the page in browser.