2010-06-29 67 views
0

我最近買了Telerik控件。我遇到了radgrid的性能問題。Radgrid性能問題更多記錄

  1. 我實現分頁到radgrid控件與6000分的記錄。我創建了rcom402_ItemCreated到radcombo的viewall選項。當我選擇viewall時,它需要20秒將數據綁定到網格,然後瀏覽器卡住(Firefox 3.6.4和IE7)並顯示錯誤(請查找附加圖像)。無論如何改變viewall選項代碼來快速獲取數據。或者無論如何改善性能並減少記錄綁定的時間。

這是我的代碼。

的.aspx代碼

style type="text/css"> 
    .rgPageFirst, .rgPagePrev, .rgPageNext, .rgPageLast 
    { 
     display: none !important; 
    } 
    div.RadGrid_Default .rgHeader, div.RadGrid_Default th.rgResizeCol 
    { 
     background-image: none; 
    } 
</style> 

<script type="text/javascript"> 
    function onRequestStart(sender, args) { 
     if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0 || 
       args.get_eventTarget().indexOf("ExportToWordButton") >= 0 || 
       args.get_eventTarget().indexOf("ExportToPdfButton") >= 0 || 
       args.get_eventTarget().indexOf("ExportToCsvButton") >= 0) { 

      args.set_enableAjax(false); 
     } 
    } 
</script> 

<div> 
    <tr> 
     <td colspan="2"> 
      <asp:Label runat="server" Font-Bold="true" Font-Size="14pt" ID="lblTskName"></asp:Label> 
     </td> 
    </tr> 
    <br /> 
</div> 
<div> 
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server"> 
    </telerik:RadScriptManager> 
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> 
     <ClientEvents OnRequestStart="onRequestStart" /> 
     <AjaxSettings> 
      <telerik:AjaxSetting AjaxControlID="rg402"> 
       <UpdatedControls> 
        <telerik:AjaxUpdatedControl ControlID="rg402" LoadingPanelID="RadAjaxLoadingPanel1" /> 
       </UpdatedControls> 
      </telerik:AjaxSetting> 
     </AjaxSettings> 
    </telerik:RadAjaxManager> 
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default"> 
    </telerik:RadAjaxLoadingPanel> 
    <telerik:RadGrid ID="rg402" runat="server" AutoGenerateColumns="false" Height="550px" 
     OnNeedDataSource="rg402_NeedDataSource" Width="120%" AllowPaging="True" AllowSorting="True" 
     AllowMultiRowSelection="True" EnableHeaderContextMenu="true" GridLines="None" 
     EnableHeaderContextFilterMenu="true" AllowMultiRowEdit="true" AllowFilteringByColumn="True" 
     OnPreRender="rg402_PreRender" OnItemCreated="rg402_ItemCreated" EnableViewState="false"> 
     <HeaderStyle HorizontalAlign="Center" BorderWidth="1px" Font-Bold="true" Font-Size="8pt" /> 
     <ExportSettings IgnorePaging="true" ExportOnlyData="true"> 
      <Pdf AllowModify="false" AllowPrinting="true" PageBottomMargin="" PageFooterMargin="" 
       PageHeaderMargin="" PageHeight="11in" PageLeftMargin="" PageRightMargin="" PageTopMargin="" 
       PageWidth="14in" /> 
     </ExportSettings> 
     <MasterTableView DataKeyNames="orderId" CommandItemDisplay="Top" EditMode="InPlace" 
      PageSize="30"> 
      <CommandItemSettings ShowExportToWordButton="true" ShowExportToExcelButton="true" 
       ShowExportToCsvButton="true" ShowExportToPdfButton="true" ShowAddNewRecordButton="false" /> 
      <Columns> 
       <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" HeaderStyle-Width="3%" 
        ItemStyle-Width="3%"> 
       </telerik:GridClientSelectColumn> 
       <telerik:GridBoundColumn UniqueName="sId" HeaderText="sId" DataField="sId" Visible="false"> 
       </telerik:GridBoundColumn> 
       <telerik:GridBoundColumn UniqueName="orderId" HeaderText="orderId" DataField="orderId" 
        Visible="false"> 
       </telerik:GridBoundColumn> 
       <telerik:GridBoundColumn UniqueName="Customer Name" HeaderText="Customer Name" DataField="Customer Name" 
        ReadOnly="true"> 
       </telerik:GridBoundColumn> 
       <telerik:GridBoundColumn UniqueName="Market Name" HeaderText="Market Name" DataField="Market Name" 
        ReadOnly="true"> 
       </telerik:GridBoundColumn> 
       <telerik:GridBoundColumn UniqueName="LOB" HeaderText="LOB" DataField="LOB" ReadOnly="true"> 
       </telerik:GridBoundColumn> 
       <telerik:GridBoundColumn UniqueName="Headend Name" HeaderText="Headend Name" DataField="Headend Name" 
        ReadOnly="true"> 
       </telerik:GridBoundColumn> 
       <telerik:GridBoundColumn UniqueName="Project Name" HeaderText="Project Name" DataField="Project Name" 
        ReadOnly="true"> 
       </telerik:GridBoundColumn> 
       <telerik:GridHyperLinkColumn UniqueName="Site Name" HeaderText="Site Name" DataTextField="Site Name"> 
       </telerik:GridHyperLinkColumn> 
       <telerik:GridBoundColumn UniqueName="Task Status" HeaderText="Task Status" DataField="Task Status" 
        ReadOnly="true"> 
       </telerik:GridBoundColumn> 
       <telerik:GridBoundColumn UniqueName="Plant Test Date" HeaderText="Plant Test Date" 
        DataField="Plant Test Date" ReadOnly="true"> 
       </telerik:GridBoundColumn> 
       <telerik:GridBoundColumn UniqueName="CORE CM Number" HeaderText="CORE CM Number" 
        DataField="CORE CM Number" ReadOnly="true"> 
       </telerik:GridBoundColumn> 
       <telerik:GridBoundColumn UniqueName="Req SM Imp Date" HeaderText="Req SM Imp Date" 
        DataField="Req SM Imp Date" ReadOnly="true"> 
       </telerik:GridBoundColumn> 
       <telerik:GridBoundColumn UniqueName="SM Ticket Number" HeaderText="SM Ticket Number" 
        DataField="SM Ticket Number"> 
       </telerik:GridBoundColumn> 
       <telerik:GridBoundColumn UniqueName="Sch SM Imp Date" HeaderText="Sch SM Imp Date" 
        DataField="Sch SM Imp Date"> 
       </telerik:GridBoundColumn> 
       <telerik:GridEditCommandColumn UniqueName="ECC402"> 
       </telerik:GridEditCommandColumn> 
      </Columns> 
     </MasterTableView> 
     <ClientSettings EnableRowHoverStyle="true" ReorderColumnsOnClient="false" AllowDragToGroup="false" 
      AllowColumnsReorder="True"> 
      <Scrolling AllowScroll="true" UseStaticHeaders="true" /> 
      <Selecting AllowRowSelect="True"></Selecting> 
      <Resizing AllowRowResize="true" AllowColumnResize="True" EnableRealTimeResize="True" 
       ResizeGridOnColumnResize="False"></Resizing> 
     </ClientSettings> 
     <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle> 
    </telerik:RadGrid> 

cs文件...

protected void Page_Load(object sender, EventArgs e) 
{ 
    try 
    { 
     if (!IsPostBack) 
     { 
      Session["SearchRes"] = null; 
      if (Session["TaskName"] != null) 
       lblTskName.Text = Session["TaskName"].ToString(); 
      Session["FilColms"] = null; 
      Session["SortExp"] = null; 
      Session["FilExp"] = null; 
      Session["ViewAll"] = null; 
      BindGrid(); 
     } 
    } 
    catch (Exception ex) 
    { 
     throw ex; 
    } 
} 

private void BindGrid() 
{ 
    try 
    { 
     DataSet dsResult = new DataSet(); 

     clsSearch_BL clsObj = new clsSearch_BL(); 
     clsObj.TaskID = (string)Session["TaskID"]; 
     clsObj.CustName = (string)Session["CustName"]; 
     clsObj.MarketName = (string)Session["MarketName"]; 
     clsObj.HeadendName = (string)Session["HeadendName"]; 
     clsObj.SiteName = (string)Session["SiteName"]; 
     clsObj.TaskStatus = (string)Session["TaskStatus"]; 
     clsObj.OrdType = (string)Session["OrdType"]; 
     clsObj.OrdStatus = (string)Session["OrdStatus"]; 
     clsObj.ProName = (string)Session["ProName"]; 
     clsObj.LOC = (string)Session["LOC"]; 
     clsObj.QuoteID = (string)Session["QuoteID"]; 
     clsObj.CMNumber = (string)Session["CMNumber"]; 

     if (Session["SearchRes"] == null) 
     { 
      dsResult = clsObj.getSearchResults_BL(clsObj); 
      Session["SearchRes"] = dsResult; 
     } 
     else 
      dsResult = (DataSet)Session["SearchRes"]; 

     DataView dataView = dsResult.Tables[0].DefaultView; 
     rg402.DataSource = dsResult; 
     //rg402.DataBind(); 
    } 
    catch (Exception ex) 
    { 
     throw ex; 
    } 
} 

protected void rg402_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) 
{ 
    BindGrid(); 
} 

protected void rg402_PreRender(object sender, EventArgs e) 
{ 
    rg402.MasterTableView.GetColumnSafe("RowIndicator").Display = false; 

} 

protected void rg402_ItemCreated(object sender, GridItemEventArgs e) 
{ 
    if (e.Item is GridPagerItem) 
    { 
     RadComboBox combo = (e.Item as GridPagerItem).FindControl("PageSizeComboBox") as RadComboBox; 

     // The number of items shown when all is selected 
     int allRowsCount = int.MaxValue; 

     // Remove duplicates 
     RadComboBoxItem duplicate = combo.Items.FindItemByValue(allRowsCount.ToString()); 
     if (duplicate != null) 
     { 
      duplicate.Remove(); 
     } 

     // Create a new item for showing all 
     RadComboBoxItem item = new RadComboBoxItem("All", allRowsCount.ToString()); 
     item.Attributes.Add("ownerTableViewId", e.Item.OwnerTableView.ClientID); 
     combo.Items.Add(item); 

     // Set the current pagesize as the selected value 
     combo.Items.FindItemByValue(rg402.PageSize.ToString()).Selected = true; 
    } 
+0

什麼與所有的會話變量?看起來你的應用沒有理由加班。 – 2010-06-29 21:00:55

回答

1

我的團隊做了radgrid控件的性能測試VS其他一些功能高度第三方控件,並radgrid控件是最快的時候...所以你在控制方面做出了很好的選擇。

瀏覽器是你的限制。你會遇到與任何控制相同的問題。一次顯示超過有用數量的數據是一種不好的做法。

6000行和16列......這可能超過9兆的HTML瀏覽器必須解析通過你的數據網格。

不要給他們一個ViewAll選項。如果他們想要快速搜索數據,則可以添加篩選結果的搜索功能。

如果他們真的想要一次所有的數據,我所做的就是在網格附近提供一個鏈接,允許他們將數據中的所有網格作爲Excel文件下載。

+0

我同意發送所有數據只是矯枉過正。限制自己5 - 7列,並實施我談到的高級分頁。然後,NestedViewTemplate可以爲每條記錄提供「更多數據」,並在模板內部擁有自己的SQLDataSource。然後,您再次針對特定數據訪問數據庫,而不是在一個大規模選擇語句中返回ALL ROWS。 – 2010-06-29 20:59:45

0

儘管我同意@Ed B的觀點,即你在網格中展示了大量數據,但我認爲舊版瀏覽器在管理你正在呈現的內存佔用情況時會遇到問題。

RadGrid中有一項新功能(截至2013年第2季度)稱爲虛擬化,可能會給您帶來性能上的提升和「查看全部」功能。

您可以在您的radgrid控件/ ClientSettings標記添加下面的標記使電網虛擬化:

<Virtualization EnableVirtualization="true" InitiallyCachedItemsCount="2000" 
        ItemsPerView="100"/> 

您可以在線演示瞭解更多的功能: http://demos.telerik.com/aspnet-ajax/grid/examples/performance/virtualization/defaultcs.aspx