I don't want RadGrid "NeedsDataSource" handler to re-query the database every time the event fires, but I do want it to act on its datasource as it is designed to do. I handle database queries in my "Search" button handler where I get a DataTable and the set RadGid's datasource equal to my datatable. Also, to persist my DataTable, I set a Session variable equal to my DataTable. Then, in RadGrid's "NeedDataSource" I set RadGrid's DataSource equal to my Session variable like the following:
protected void BindDataTable( DataTable dt)
{
RadGrid1.DataSource = dt;
RadGrid1.DataBind();
RadGrid1.CurrentPageIndex = 1;
Session["RADGRIDSOURCE"] = dt;
}
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
RadGrid1.DataSource = Session["RADGRIDSOURCE"];
}
I am questioning weather this is the best approach or not. Is there a better way?
protected void BindDataTable( DataTable dt)
{
RadGrid1.DataSource = dt;
RadGrid1.DataBind();
RadGrid1.CurrentPageIndex = 1;
Session["RADGRIDSOURCE"] = dt;
}
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
RadGrid1.DataSource = Session["RADGRIDSOURCE"];
}
I am questioning weather this is the best approach or not. Is there a better way?