+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Caching datasource / Performance improvement while databinding to gridview

Caching datasource / Performance improvement while databinding to gridview

2 posts, 0 answered
  1. Praneeth
    Praneeth avatar
    26 posts
    Registered:
    22 Jun 2012
    02 Aug 2014
    Link to this post

    Hi Team,

     I am able to bind gridview with paging enabled in Sitefinity 7.0. The problem is I have approximately 2.5 lakh records which is huge. So I wanted to either make it a server side paging or cache the entire datasource. I failed in both. Please look at my code below both ascx and ascx.cs. The code am pasting here is calling the method BindProducts() for every click which makes it a performance problem. Please help

    ASCX

     <asp:GridView AllowPaging="true" GridLines="None" OnPageIndexChanging="gvProducts_PageIndexChanging" PagerStyle-CssClass="paging"
                PageSize="10" CssClass="product-list desktop-product-list" runat="server" ID="gvProducts" AutoGenerateColumns="false">
                <Columns>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <asp:Label ID="lblSKUHdr" runat="server" Text="SKU"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <span data-title="SKU"><%#Eval("SKU") %></span>
                        </ItemTemplate>

                    </asp:TemplateField>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <asp:Label ID="lblProdutNameHdr" runat="server" Text="Name"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>

                            <a href='<%# string.Concat(BaseUrl,"/?sku=",Eval("SKU")) %>'><%#Eval("Title") %></a>
                        </ItemTemplate>

                    </asp:TemplateField>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <asp:Label ID="lblMfrHdr" runat="server" Text="Manufacturer"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            BIO-RAD Laboratories
                        </ItemTemplate>

                    </asp:TemplateField>

                    <asp:TemplateField>
                        <HeaderTemplate>
                            <asp:Label ID="lblSizeHdr" runat="server" Text="Size"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            EA
                        </ItemTemplate>

                    </asp:TemplateField>

                    <asp:TemplateField>
                        <HeaderTemplate>
                            <asp:Label ID="lblPriceHdr" runat="server" Text="Price"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            $15.00
                        </ItemTemplate>

                    </asp:TemplateField>

                    <asp:TemplateField>
                        <HeaderTemplate>
                            <asp:Label ID="lblStockHdr" runat="server" Text="Stock"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            Special Order
                        </ItemTemplate>

                    </asp:TemplateField>

                    <asp:TemplateField>

                        <ItemTemplate>
                            Add to cart
                        </ItemTemplate>

                    </asp:TemplateField>

                </Columns>
            </asp:GridView>

    Ascx.cs


            private string _baseURL;

            public string BaseUrl
            {
                get { return _baseURL; }
                set
                {
                    _baseURL = this.ResolveUrl(value);

                }
            }


            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    BindProducts();
                }
            }


            public void BindProducts()
            {
                try
                {
                    CatalogManager catalogManager = CatalogManager.GetManager();
                    gvProducts.DataSource = catalogManager.GetProductsInStockAndActive();
                    gvProducts.DataBind();
                }
                catch (Exception ex)
                {
                    Log.Write(ex, System.Diagnostics.TraceEventType.Error);
                }
            }

            protected void gvProducts_PageIndexChanging(object sender, GridViewPageEventArgs e)
            {
                gvProducts.PageIndex = e.NewPageIndex;
                BindProducts();
            }
        }

     

     

  2. Ivan D. Dimitrov
    Ivan D. Dimitrov avatar
    310 posts
    Registered:
    26 Mar 2015
    06 Aug 2014
    Link to this post
    Hi Praneth,

    Binding your data on every postback cannot go without performance problems. What you can do in order to avoid them is to use Telerik's RadGrid. The RadGrid presents the NeedDataSource event which is part enables you to do advanced binding thus lowering the performance overhead.

    Regards,
    Ivan D. Dimitrov
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
2 posts, 0 answered