This demo illustrates the optimized performance techniques incorporated in the ASP.NET
3.5 build of RadGrid. The control takes advantage of the new LINQ (Language Integrated
Query) syntax introduced in ASP.NET 3.5 and performs aggregate calculations or executes
sorting/filtering/paging operations by means of native LINQ expressions. This technique
significantly reduces the time necessary to process these actions "behind the scenes"
and allows you to handle millions of records within a few milliseconds.
Please bear in mind that
these optimizations are available only in the ASP.NET 3.5 build of the grid (the
assembly resides in the /bin35 folder of the installation).
ASPX/ASCX
<telerik:RadGrid ID="RadGrid1" EnableLinqExpressions="true" Skin="Hay" DataSourceID="LinqDataSource1"
AllowFilteringByColumn="true" AllowPaging="true" AllowSorting="true" runat="server">
<PagerStyle Mode="NextPrevAndNumeric" />
</telerik:RadGrid>
<asp:LinqDataSource ID="LinqDataSource1" AutoPage="false" runat="server"
ContextTypeName="DataClassesDataContext" TableName="MyTables">
</asp:LinqDataSource>
C#
Stopwatch watch = new Stopwatch();
Stopwatch retrieveWatch = new Stopwatch();
protected void Page_Init(object sender, EventArgs e)
{
watch.Reset();
watch.Start();
LinqDataSource1.Selecting += new EventHandler<LinqDataSourceSelectEventArgs>(LinqDataSource1_Selecting);
LinqDataSource1.Selected += new EventHandler<LinqDataSourceStatusEventArgs>(LinqDataSource1_Selected);
}
void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
e.Arguments.TotalRowCount = 1000000;
if (CheckBox3.Checked)
{
if (Cache["MyData"] != null)
{
e.Result = Cache["MyData"];
}
}
retrieveWatch.Reset();
retrieveWatch.Start();
}
void LinqDataSource1_Selected(object sender, LinqDataSourceStatusEventArgs e)
{
if (CheckBox3.Checked)
{
if (Cache["MyData"] == null)
{
Cache["MyData"] = e.Result;
}
}
retrieveWatch.Stop();
}
protected override void Render(HtmlTextWriter writer)
{
watch.Stop();
Label1.Text = retrieveWatch.ElapsedMilliseconds.ToString();
Label2.Text = (watch.ElapsedMilliseconds - retrieveWatch.ElapsedMilliseconds).ToString();
Label3.Text = watch.ElapsedMilliseconds.ToString();
base.Render(writer);
}