【问题标题】:Telerik RadGrid binding to large DataTableTelerik RadGrid 绑定到大型 DataTable
【发布时间】:2014-01-10 18:43:49
【问题描述】:

我已经成功地将 RadGrid 绑定到需要冗长查询才能生成的大型 DataTable。我的问题是 RadGrid 只会显示一个页面,并且必须在用户更改页面时回发,我丢失了我的 DataTable,必须再次执行这个巨大的查询。

我尝试对 RadGrid 进行 Ajaxify,但它仍然调用 Page_Load,因此我无法保存我的 DataTable。 (它应该这样做吗?)

我可以做些什么不同的事情?谢谢。

    <telerik:RadAjaxManager runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="rgReport">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="rgReport" 
                            LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>

            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
        </Scripts>
    </telerik:RadScriptManager>
                <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" IsSticky="False" Style="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;"  EnableSkinTransparency="true" Transparency="0">
</telerik:RadAjaxLoadingPanel>

 <telerik:RadGrid ID="rgReport" runat="server" AllowPaging="True" PageSize="50" 
                    AllowSorting="True" OnNeedDataSource="rgReport_NeedsDataSource" OnItemCommand="rgReport_ItemCommand"
                    AutoGenerateColumns="False" ShowStatusBar="True" CellSpacing="0" 
                    GridLines="None">
                    <ClientSettings>
                        <ClientEvents OnRowMouseOver="CBGridRowMouseOver" OnRowMouseOut="CBGridRowMouseOut" /> 
                    </ClientSettings>
                    <MasterTableView Width="100%" DataKeyNames="submissionID"  Name="Master">
                        <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
                        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" 
                            Visible="True">
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" 
                            Visible="True">
                        </ExpandCollapseColumn>
                        <Columns>
                            <telerik:GridBoundColumn SortExpression="customerID" HeaderText="customerID" HeaderButtonType="None" 
                                DataField="customerID">
                            </telerik:GridBoundColumn>

【问题讨论】:

    标签: c# asp.net telerik-grid


    【解决方案1】:

    将该数据表存储在服务器端的cache 中,当然,如果您这样做,您应该管理该缓存,例如。如果数据发生变化,清除它。

    现在您的代码应该如下所示:

    string cacheID = "myCacheID"; 
    DataTable data = null;
    if (HttpContext.Current.Cache[cacheID] == null)
    {
      data = GetThatHugeDataTable();
      HttpContext.Current.Cache.Insert(cacheID, data);
    }
    else
    {
      data = (DataTable)HttpContext.Current.Cache[cacheID];
    }
    

    当数据改变时清除缓存:

    HttpContext.Current.Cache.Remove(cacheID);
    

    请注意,这会在 Web 服务器上消耗大量内存,当然这取决于 DataTable 的大小。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-27
      • 2010-10-07
      • 2013-07-02
      • 1970-01-01
      • 1970-01-01
      • 2016-09-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多