Friday, February 10, 2012

GridView Paging in

In this post, i'm going to share to code snippet for gridview paging using with c#
This example is simple and understandable code using with c#
In the 1st step, we write the code for business logic code in page i.e. .aspx.cs

   protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
                GridView1.PageIndex = e.NewPageIndex;
            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, we write the code for view in page i.e. .aspx

<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">
                            <asp:BoundField DataField="dateTime" HeaderText="Uploaded Date">                        
                            <asp:BoundField DataField="filename" HeaderText="Videos Name">
                            <asp:BoundField DataField="filePath" HeaderText="Videos path" 

                                    <asp:LinkButton ID="lkbVideo" runat="server" Font-Bold="True"