Hold On

Hold On

  • 1.2k
  • 1.1k
  • 211.1k

Effective Paging in a Gridview From a Stored Procedure

May 8 2021 12:42 PM
Hello everyone,
 
I found this article "https://www.codeproject.com/Articles/125541/Effective-Paging-with-GridView-Control-in-ASP-NET" which explains how to implement an effective sorting. Unfortunately, the author is using an ObjectDataSource to display the data to the grid view while I am displaying the data from the code behind. Can someone help me to implement his idea from the code behind? Below is the gridview and ObjectDataSource mark-up
 
  1. <div>  
  2.         <asp:GridView ID="gvProfile" DataSourceID="profileDataSource" runat="server" AutoGenerateColumns="false"  
  3.             AllowPaging="true" AllowSorting="true" PageSize="5" HeaderStyle-Font-Names="Verdana"   
  4.             Font-Size="Small" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Font-Underline="false"  
  5.             Width="55%" HeaderStyle-BackColor="BurlyWood" HeaderStyle-ForeColor="Navy">  
  6.             <AlternatingRowStyle BackColor="Aquamarine" />  
  7.             <Columns>  
  8.                 <asp:BoundField DataField="ProfileId" HeaderText="Profile Id" SortExpression="ProfileId"  
  9.                     ItemStyle-Width="6%" />  
  10.                 <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" ItemStyle-Width="13%" />  
  11.                 <asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address"  
  12.                     ItemStyle-Width="18%" />  
  13.                 <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" ItemStyle-Width="8%" />  
  14.                 <asp:BoundField DataField="Mobile" HeaderText="Mobile" SortExpression="Mobile" ItemStyle-Width="9%" />  
  15.                 <asp:BoundField DataField="IsActive" HeaderText="Status" SortExpression="IsActive" ItemStyle-Width="4%" />  
  16.             </Columns>  
  17.         </asp:GridView>  
  18.     </div>  
  19.     </center>  
  20.     <asp:ObjectDataSource ID="profileDataSource" runat="server" SelectMethod="GetProfileData" EnablePaging="true" MaximumRowsParameterName="pageSize"  
  21.         StartRowIndexParameterName="startRowIndex" TypeName="VTS.Web.UI.ProfileDataSource"  SelectCountMethod="TotalRowCount"   
  22.         SortParameterName="sortExpression">  
  23.         <SelectParameters>  
  24.             <asp:Parameter Name="startRowIndex" Type="Int32" />  
  25.             <asp:Parameter Name="pageSize" Type="Int32"/>  
  26.             <asp:Parameter Name="sortExpression" Type="String" />              
  27.         </SelectParameters>  
  28.     </asp:ObjectDataSource>  
Thank you in advance. 

Answers (2)