This is a migrated thread and some comments may be shown as answers.

Grid binding is too slow when retrieving large database

3 Answers 373 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Manu
Top achievements
Rank 1
Manu asked on 14 Feb 2011, 04:05 AM
Hi,

I am working on a project that have developed by previous developers. In this project, there is a RadGrid which is used to manage the members. The member details are fetched from the database using a stored procedure and is binding it to the RadGrid. When the number of members is large, it takes a very long time to load the grid. I have checked the code and found that the ItemDatabound event of the grid creates the problem. There are some checking in this event which required to load the values in the grid. The html part of the grid is :

 

<telerik:RadGrid ID="radGvMembers" runat="server" AllowPaging="True" AutoGenerateColumns="false"
                            GridLines="None" OnNeedDataSource="radGvMembers_NeedDataSource" AllowAutomaticDeletes="True"
                            AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowSorting="true"
                            AllowFilteringByColumn="True" OnUpdateCommand="radGvMembers_UpdateCommand" OnDeleteCommand="radGvMembers_DeleteCommand"
                            OnInsertCommand="radGvMembers_InsertCommand" OnItemCommand="radGvMembers_ItemCommand"
                            OnItemDataBound="radGvMembers_ItemDataBound" OnPreRender="radGvMembers_PreRender"
                            AllowMultiRowSelection="true" OnPageIndexChanged="radGvMembers_PageIndexChanged"
                            OnGridExporting="radGvMembers_GridExporting" Width="780px" OnSortCommand="radGvMembers_SortCommand">
                            <GroupingSettings CaseSensitive="false" />
                            <MasterTableView DataKeyNames="MemberId,IsBounced" CommandItemDisplay="Top" AllowCustomSorting="false"
                                Width="100%">
                                <ExpandCollapseColumn>
                                    <HeaderStyle Width="20px" />
                                </ExpandCollapseColumn>
                                <CommandItemTemplate>
                                    <div>
                                        <table width="100%">
                                            <tr>
                                                <td align="left">
                                                    <asp:LinkButton ID="linkAddButton" runat="server" CommandName="InitInsert">Add New Member</asp:LinkButton>
                                                </td>
                                                <td align="right">
                                                    <asp:LinkButton ID="linkRefresh" runat="server" CommandName="RebindGrid">Refresh</asp:LinkButton>
                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                </CommandItemTemplate>
                                <Columns>
                                    <telerik:GridClientSelectColumn DataType="System.Boolean">
                                    </telerik:GridClientSelectColumn>
                                    <telerik:GridEditCommandColumn ButtonType="ImageButton" DataType="System.Guid" UniqueName="EditColumn">
                                    </telerik:GridEditCommandColumn>
                                    <telerik:GridButtonColumn ButtonType="ImageButton" ConfirmDialogType="RadWindow"
                                        ConfirmText="Do you want to delete?" ConfirmTitle="Delete" Text="Delete" CommandArgument="MemberId"
                                        CommandName="Delete" UniqueName="DeleteColumn">
                                    </telerik:GridButtonColumn>
                                    <telerik:GridTemplateColumn UniqueName="ReinstateMember" AllowFiltering="false">
                                        <ItemTemplate>
                                            <asp:ImageButton ID="btnReinstateMember" runat="Server" CommandName="ReInstate" />
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn UniqueName="Subscribe" AllowFiltering="false" HeaderText="IsSubscribed"
                                        SortExpression="IsSubscribed" DataField="IsSubscribed" DataType="System.Boolean">
                                        <ItemTemplate>
                                            <asp:CheckBox ID="IsSubscribed" runat="server" Checked='<%#Eval("IsSubscribed")%>'
                                                Enabled="false" />
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn DataField="IsBounced" SortExpression="IsBounced" AllowFiltering="false"
                                        UniqueName="BounceMember">
                                        <ItemTemplate>
                                            <asp:LinkButton ID="btnBounceMember" runat="Server" CommandName="BounceMember" Text="Button" />
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                </Columns>
                                <RowIndicatorColumn>
                                    <HeaderStyle Width="20px" />
                                </RowIndicatorColumn>
                                <EditFormSettings>
                                    <EditColumn UniqueName="EditCommandColumn1">
                                    </EditColumn>
                                </EditFormSettings>
                            </MasterTableView>
                            <FilterMenu EnableTheming="True">
                                <CollapseAnimation Duration="200" Type="OutQuint" />
                            </FilterMenu>
                            <ExportSettings ExportOnlyData="false" OpenInNewWindow="true" IgnorePaging="true">
                            </ExportSettings>
                            <ClientSettings AllowColumnHide="false">
                                <Scrolling AllowScroll="True" UseStaticHeaders="True"></Scrolling>
                                <Selecting AllowRowSelect="True" />
                            </ClientSettings>
                        </telerik:RadGrid>

and the code in the ItmeDataBound event is:

protected void radGvMembers_ItemDataBound(object sender, GridItemEventArgs e)
        {
            try
            {
                if (e.Item is GridDataItem)
                {
  
                    ImageButton btnReinstate = ((GridDataItem)e.Item).FindControl("btnReinstateMember") as ImageButton;
                    if (e.Item.Cells[6].Text == "True")
                    {
                        e.Item.Cells[1].Text = String.Empty;
                        e.Item.Cells[2].Text = String.Empty;
                        e.Item.Cells[4].Visible = false;
                        e.Item.Cells[6].Text = string.Empty;
                        e.Item.Cells[3].Enabled = false;
                        btnReinstate.ImageUrl = "~/App_Themes/Default/Grid/undo.jpg";
                        btnReinstate.OnClientClick = "return radconfirmWindow('Are you sure want to Re-Instate the Member'," +
                                                  "'" + btnReinstate.UniqueID + "','100','300','Member Management');";
                        (e.Item as GridDataItem).BackColor = System.Drawing.Color.Gray;
                    }
                    else
                    {
                        e.Item.Cells[6].Visible = false;
                        btnReinstate.Visible = false;
                    }
  
  
                    bool BouncedMemberStatus = Convert.ToBoolean(e.Item.OwnerTableView.DataKeyValues[e.Item.
                                        ItemIndex]["IsBounced"].ToString());
  
                    LinkButton btnBounced = ((GridDataItem)e.Item).FindControl("btnBounceMember") as LinkButton;
                    btnBounced.CommandArgument = BouncedMemberStatus.ToString();
                    btnBounced.Width = Unit.Pixel(80);
  
                    //Set Client Script
                    if (BouncedMemberStatus)
                    {
                        btnBounced.Text = "UnBounce";
                        btnBounced.OnClientClick = "return radconfirmWindow('Are you sure want to UnBounce the Member'," +
                                                   "'" + btnBounced.UniqueID + "','100','300','Bounce Management');";
                    }
                    else
                    {
                        btnBounced.Text = "Bounce";
                        btnBounced.OnClientClick = "return radconfirmWindow('Are you sure want to Bounce the Member'," +
                                                   "'" + btnBounced.UniqueID + "','100','300','Bounce Management');";
                    }
                }
                else if (e.Item is GridHeaderItem || e.Item is GridFilteringItem || e.Item is GridFooterItem)
                {
                    e.Item.Cells[6].Visible = false;
                    if (e.Item is GridHeaderItem)
                    {
                        CheckBox chk = ((GridHeaderItem)e.Item).FindControl("headerChkbox") as CheckBox;
                        if (chk != null)
                        {
                            chk.Checked = AreAllMembersSelected;
                        }
                    }
                }
            }
            catch (Exception Excep)
            {
                logger.Error("Error Trace on  " + System.Reflection.MethodBase.GetCurrentMethod().Name, Excep);
                Response.Redirect("~/ErrorPages/GenericErrorShow.aspx?msg=" + Excep.Message);
            }
        }

How can we speed up the execution of the page? Please advice me.

3 Answers, 1 is accepted

Sort by
0
Manu
Top achievements
Rank 1
answered on 16 Feb 2011, 05:25 AM
Anyone can help?
0
Pavlina
Telerik team
answered on 16 Feb 2011, 11:31 AM
Hi Manu,

Useful tips on how to optimize the RadGrid performance using different techniques can be found in the online resources linked below:

http://www.telerik.com/help/aspnet-ajax/gridoverview.html (Chapter "Performance tips and tricks")
http://www.telerik.com/products/aspnet-ajax/resources/top-performance.aspx
http://www.telerik.com/support/aspnet-ajax.aspx (Section "Performance")

Greetings,
Pavlina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Manu
Top achievements
Rank 1
answered on 17 Feb 2011, 06:36 AM
Thanks Pavlina,

I will check out the links.

Tags
Grid
Asked by
Manu
Top achievements
Rank 1
Answers by
Manu
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or