How to implement Custom Paging and Sorting in ASP.Net Gridview
In one of my previous article I have explained How to implement Custom Paging in ASP.Net GridView using SQL Server Stored Procedure . In this article I would like to explain how to implement custom paging and sorting in ASP.Net GridView.
Displaying data in ASP.NET Webform is very simple task using GridView with some great (default) functionality like sorting and paging. We can use Gridview's default paging by setting it's property AllowPaging="true" and sotring by setting AllowSorting="True". The GridView will show the pager itself depending on the PageSize and total records. But this way is very tedious and degrades the performance of the application because everytime the PageIndex changes, the GridView will be bound with the complete datasource that is not required at all, as we need to show only data to the corresponding PageIndex. To improve the performance of the web application I am going to explain how to implement custom paging and oorting in ASP.Net GridView.

SL ID Rank Company Name Revenue Industry
11Indian Oil Corporation Ltd.416816.20Refineries
22Reliance Industries Ltd.364695.00Diversified
33Bharat Petroleum Corporation Ltd.213596.23Refineries
44Hindustan Petroleum Corporation Ltd.186327.55Refineries
55State Bank of India177032.83Finance - Banks - Public Sector
66Tata Motors Ltd.166316.27Auto - LCVs/HCVs
77Oil And Natural Gas Corporation Ltd.154147.27Oil Drilling And Exploration
88Tata Steel Ltd.137834.66Steel
99Coal India Ltd.82641.61Mining/Minerals
1010Hindalco Industries Ltd.81604.44Aluminium
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="ASPGridPagingSorting.SiteMaster" %>

<!DOCTYPE html>
<html lang="en">
<head runat="server">
    <meta charset="utf-8" />
    <title><%: Page.Title %> - My ASP.NET Application</title>
    <link href="~/Content/Site.css" rel="stylesheet" /> 
    <link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />
    <asp:PlaceHolder runat="server">        
        <script src="<%: ResolveUrl("~/Scripts/modernizr-2.5.3.js") %>"></script>
    </asp:PlaceHolder>
    <meta name="viewport" content="width=device-width" />
    <asp:ContentPlaceHolder runat="server" ID="HeadContent" />
</head>
<body>
    <form runat="server">
    <asp:ScriptManager runat="server">
        <Scripts>
            <asp:ScriptReference Name="jquery" />
            <asp:ScriptReference Name="jquery.ui.combined" />
        </Scripts>
    </asp:ScriptManager>
    <header>
        <div class="content-wrapper">
            <div class="float-left">
                <p class="site-title"><a runat="server" href="~/">your logo here</a></p>
            </div>
            <div class="float-right">
                <section id="login">
                    <asp:LoginView runat="server" ViewStateMode="Disabled">
                        <AnonymousTemplate>
                            <ul>
                                <li><a id="registerLink" runat="server" href="~/Account/Register.aspx">Register</a></li>
                                <li><a id="loginLink" runat="server" href="~/Account/Login.aspx">Log in</a></li>
                            </ul>
                        </AnonymousTemplate>
                        <LoggedInTemplate>
                            <p>
                                Hello, <a runat="server" class="username" href="~/Account/Manage.aspx" title="Manage your account">
                                    <asp:LoginName runat="server" CssClass="username" />
                                </a>!
                                <asp:LoginStatus runat="server" LogoutAction="Redirect" LogoutText="Log off" LogoutPageUrl="~/" />
                            </p>
                        </LoggedInTemplate>
                    </asp:LoginView>
                </section>
                <nav>
                    <ul id="menu">
                        <li><a runat="server" href="~/">Home</a></li>
                        <li><a runat="server" href="~/About.aspx">About</a></li>
                        <li><a runat="server" href="~/Contact.aspx">Contact</a></li>
                    </ul>
                </nav>
            </div>
        </div>
    </header>
    <div id="body">
        <asp:ContentPlaceHolder runat="server" ID="FeaturedContent" />
        <section class="content-wrapper main-content clear-fix">
            <asp:ContentPlaceHolder runat="server" ID="MainContent" />
        </section>
    </div>
    <footer>
        <div class="content-wrapper">
            <div class="float-left">
                <p>&copy; <%: DateTime.Now.Year %> - My ASP.NET Application</p>
            </div>
        </div>
    </footer>
    </form>
</body>
</html>
Posted By : Sourav Mondal