Skip to content

Page index change for large gridview that has huge data

Osama Shatnawe

Asked Aug 30, 2014, 4:26 AM EDT3 answers
Share
LinkedInX
Hi,
 
I would like to ask you for a method to page index change for large gridview that has large  data becouse the page index change of this grid is so slow.
 
 
 
Thanks.

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Vasanth Krishnan
    +1
    Can you please let me know whether that is the normal asp grid view or some other third party grid view.
    +1
  • 0
    yes it's a normal asp.net gridview
    0
  • Vasanth Krishnan
    0
    Try this one and let me know the result.

    Add this method in the asp:Grid in aspx page

    //Add OnPageIndexChanging and PageSize="30" as shown below.
    <asp:GridView OnPageIndexChanging="gvProduct_PageIndexChanging"  PagerStyle-ForeColor="#ffab66" runat="server" ShowHeader="true" AllowPaging="true"
                            PagerSettings-Position="TopAndBottom" PagerStyle-Font-Bold="true" PageSize="30"
                            PagerStyle-HorizontalAlign="Right" AutoGenerateColumns="False" CellPadding="1"
                            Font-Bold="False" Font-Names="Arial, Helvetica, sans-serif" Font-Size="12px">
                            <PagerStyle CssClass="pager" />
                            <PagerSettings Position="TopAndBottom"></PagerSettings>
                            <Columns>
                               
                            </Columns>
      </asp:GridView>

    //Add this line in the code behind

    protected void gvProduct_PageIndexChanging(object sender, System.Web.UI.WebControls.GridViewPageEventArgs e)
        {
            string sMonth = ddlMonth.SelectedItem.Value;
            string sYear = ddlYear.SelectedItem.Value;

            try
            {
                string sCompanyCode = Session["CompanyCode"].ToString();
                ds = new DataSet();
                dt = new System.Data.DataTable();
              
    //Retrieve the data set and assign it to data table

                gvEmployee.PageIndex = e.NewPageIndex;
                gvEmployee.DataSource = dt;
                gvEmployee.DataBind();
            }
            catch (Exception ex)
            {
            }
            finally
            {
                clsCommon.CloseDB();
            }
        }

    I just give u the idea. Please try this and let me know the status if u wish.
    Thanks
    0