Telerik RadGrid绑定到大型DataTable

时间:2014-01-10 18:43:49

标签: c# asp.net telerik-grid

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

我尝试Ajaxify RadGrid,但它仍然调用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>

1 个答案:

答案 0 :(得分:0)

将DataTable存储在服务器端的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的大小。