Why we need to go for Lazy loading and Custom Paging
Whenever you want to display data in Gridview, that data might contain lacks of records. If you show all data at a time, it will take more time to get the data also you may get timed out error in application. When we need to display only some of the records in Gridview and table in database contains lacks of records then we should have to use lazy loading with custom paging instead of default paging.
Stored Procedure with Pagination:
- CREATEPROCEDUREGetAll_Employees
- @pageIndexint,
- @pageSizeint,
- @totalRecordsintOUTPUT
- -- EXEC GetAll_Employees 1, 100,@totalRecords OUTPUT;PRINT @totalRecords
- AS
- BEGIN
- SELECT@totalRecords=COUNT(EmpID)FROMdbo.Employees
- SelectEmpID,EmpName,Desigantion,Address,Cityfrom
- (
- Select
- Row_number()over(OrderbyEmpIDASC)asRowNo,
- EmpName,Desigantion,Address,City
- FROMdbo.Employees
- )ASEmp
- Where
- Emp.RowNobetween((@pageIndex- 1)*@pageSize)+ 1 and(@pageIndex*@pageSize)
- OrderbyEmpIDASC
- END
- <asp:GridViewIDasp:GridViewID="grdEmployee"runat="server"AutoGenerateColumns="false">
- <Columns>
- <asp:BoundFieldHeaderTextasp:BoundFieldHeaderText="EmpID"DataField="EmpID"/>
- <asp:BoundFieldHeaderTextasp:BoundFieldHeaderText="EmpName"DataField="EmpName"/>
- <asp:BoundFieldHeaderTextasp:BoundFieldHeaderText="Address"DataField="Address"/>
- <asp:BoundFieldHeaderTextasp:BoundFieldHeaderText="City"DataField="City"/>
- </Columns>
- </asp:GridView>
- <br/>
- <asp:RepeaterIDasp:RepeaterID="rptPager"runat="server">
- <ItemTemplate>
- <asp:LinkButtonCssClassasp:LinkButtonCssClass="abc"ID="lnkPage"runat="server"Text='<%#Eval("Text") %>'CommandArgument='<%# Eval("Value") %>'Enabled='<%# Eval("Enabled") %>'OnClick="Page_Changed">
- </asp:LinkButton>
- </ItemTemplate>
- </asp:Repeater>



Santhakumar MunuswamyPosted Jul 12, 2015, 12:06 AM
Nice one