Paging in GridView using c# .net

Paging in GridView using c# .net

In this post, i'm going to share to code snippet for gridview paging using asp.net with c#
This example is simple and understandable code using asp.net with c#

In the 1st step, code sample for business logic code in asp.net page i.e. .aspx.cs as given below.


 protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
  {
            try
            {
                GridView1.PageIndex = e.NewPageIndex;
                GetGroupsList();
            }
            catch (Exception ex)
            {
                throw ex;
            }
  }

  /// <returns>DataSet</returns>
  public DataSet GetgroupsList()
   {
            DataSet dsGroupsList = null;
            string spName = "sp_GetAllGroups";
            Hashtable paramTable = new Hashtable();
            dsGroupsList = DataAccess.ExecuteSP(spName, paramTable);
            return dsGroupsList;
   }
  
In the 2nd step, code sample for UX view in asp.net page i.e. .aspx as given below.

<asp:gridview id="GridView1" runat="server" autogeneratecolumns="False" pagesize="8"
    width="100%" allowpaging="true" backcolor="White" bordercolor="#CCCCCC"
    borderstyle="None" onpageindexchanging="GridView1_PageIndexChanging"
    borderwidth="1px" cellpadding="4" forecolor="Black" gridlines="Horizontal">
    <Columns>
        <asp:BoundField DataField="dateTime" HeaderText="Uploaded Date">                 
        </asp:BoundField>
        <asp:BoundField DataField="filename" HeaderText="Videos Name">
        </asp:BoundField>
        <asp:BoundField DataField="filePath" HeaderText="Videos path" InsertVisible="false">                 
        </asp:BoundField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:LinkButton ID="lkbVideo" runat="server" Font-Bold="True" OnClick="lkbVideo_Click">Play</asp:LinkButton>
            </ItemTemplate>                               
        </asp:TemplateField>
    </Columns>               

</asp:gridview>




ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.
^