Telerik Grid Version: Telerik Grid ASP. NET AJAX Q1 2010 SP1
Requirements:
We need to build a self-referencing RadGrid with custom columns (ca 200 - 500 columns), inline editing and yahoo scrolling (ca 500 - 5000 rows).
- Why Custom columns
The grid datasource should have 24 x 5 = 120 columns at least but the grid itself should show at least 24 columns (2 years = 2 x 12 months).
However, each row should show the content of 5 fields (that's why we need overall 24 x 5 = 120 columns).
- Why inline Edit
The user should be able to edit only 1 of the 5 fields per row. We tried double edit click, but for performance reason, it didnt work well.
- Why yahoo scrolling
To improve performance and for better usability, the user shouldnt wait before all the rows are rendered before editing them.
- Why self-referencing
The grid shows tasks with level and outline numbers. The user want to see a hierarchy, so he can collapse/expand task from any level.
See the picture "preview" in attachment to see how the grid currently looks
Problem:
We could successfully implement the grid with custom column, inline editing and yahoo scrolling. Everything so far is working fine.
Our only problem now is to make the grid self-referencing.
When trying this, we have an Error "System.OutOfMemoryException".
When debugging, we found that, this error occurs just after RadGrid1_NeedDataSource in RadGrid1_ColumnCreated
We suspect that the problem has to do with the huge amount of columns (around 100) and the fact that we enable self-referencing.
Any Idea or suggestions?
Code:
The grid is created programmatically because the columns are created dynamically.
aspx : The grid will be later added in PlaceHolder1
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
OnAjaxRequest
=
"RadAjaxManager1_AjaxRequest"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadGrid1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
LoadingPanelID
=
"RadAjaxLoadingPanel1"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"Label1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadAjaxManager1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
LoadingPanelID
=
"RadAjaxLoadingPanel1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
<
ClientEvents
/>
</
telerik:RadAjaxManager
>
<
telerik:RadAjaxLoadingPanel
runat
=
"server"
ID
=
"RadAjaxLoadingPanel1"
Height
=
"75px"
Width
=
"75px"
Transparency
=
"25"
/>
<
telerik:RadAjaxPanel
runat
=
"server"
ID
=
"RadAjaxPanel1"
LoadingPanelID
=
"RadAjaxLoadingPanel1"
>
<
asp:PlaceHolder
runat
=
"server"
ID
=
"PlaceHolder1"
>
</
asp:PlaceHolder
>
<
br
/>
<
asp:Label
ID
=
"L_Text_LastChange"
runat
=
"server"
Text
=
"Last change on: "
CssClass
=
"labelText"
></
asp:Label
>
</
telerik:RadAjaxPanel
>
page_init
protected
void
Page_Init(
object
sender, EventArgs e)
{
RadGrid1.ID =
"RadGrid1"
;
RadGrid1.AllowMultiRowEdit =
true
;
RadGrid1.AllowMultiRowSelection =
true
;
RadGrid1.GroupingEnabled =
true
;
RadGrid1.Skin =
"Windows7"
;
RadGrid1.Width = Unit.Percentage(97);
//the initial amount of rows to show
RadGrid1.PageSize = 20;
//20
RadGrid1.AllowPaging =
true
;
RadGrid1.AllowSorting =
true
;
RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
RadGrid1.AutoGenerateColumns =
false
;
RadGrid1.GridLines = GridLines.None;
RadGrid1.ShowFooter =
false
;
//PagerStyle
RadGrid1.PagerStyle.Visible =
false
;
//MasterTableView
RadGrid1.MasterTableView.TableLayout = GridTableLayout.Fixed;
RadGrid1.MasterTableView.AutoGenerateColumns =
true
;
RadGrid1.MasterTableView.EditMode = GridEditMode.InPlace;
//ClientSettings
RadGrid1.ClientSettings.Scrolling.ScrollHeight = Unit.Pixel(350);
//350
//Yahoo Scrolling
RadGrid1.ClientSettings.Scrolling.AllowScroll =
true
;
RadGrid1.ClientSettings.Scrolling.UseStaticHeaders =
true
;
RadGrid1.ClientSettings.Scrolling.SaveScrollPosition =
true
;
RadGrid1.ClientSettings.ClientEvents.OnScroll =
"HandleScrolling"
;
//Because of ClientSelectColumn
RadGrid1.ClientSettings.Selecting.AllowRowSelect =
true
;
//Custom row selection
RadGrid1.ClientSettings.ClientEvents.OnRowSelected =
"SelectRows"
;
RadGrid1.ClientSettings.ClientEvents.OnRowDeselected =
"DeSelectRows"
;
//Add editColumn
RadGrid1.MasterTableView.DataKeyNames =
new
string
[] {
"ID"
, STR_TaskOutlineNumber, ColName_TaskName, STR_TaskLevel,
"SAPInternalIDTask"
,
"SAPSystem"
, STR_HasChanged, STR_ColumnChanged };
RadGrid1.MasterTableView.ClientDataKeyNames = RadGrid1.MasterTableView.DataKeyNames;
//Add custom column
addCustomColumns(RadGrid1, gridSource);
//Set Grid Events
RadGrid1.PreRender +=
new
EventHandler(RadGrid1_PreRender);
RadGrid1.ColumnCreated +=
new
GridColumnCreatedEventHandler(RadGrid1_ColumnCreated);
RadGrid1.UpdateCommand +=
new
GridCommandEventHandler(RadGrid1_UpdateCommand);
RadGrid1.NeedDataSource +=
new
GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource);
//Add the grid to the placeholder
this
.PlaceHolder1.Controls.Add(RadGrid1);
//TODO: Not working, throw error "System.OutOfMemoryException", need help here!!!
//Build self-referencing
//RadGrid1.MasterTableView.HierarchyLoadMode = GridChildLoadMode.Client;
//RadGrid1.MasterTableView.HierarchyDefaultExpanded = true;
//RadGrid1.MasterTableView.SelfHierarchySettings.ParentKeyName = "ParentNr";
//RadGrid1.MasterTableView.SelfHierarchySettings.KeyName = "Nr";
//RadGrid1.ClientSettings.AllowExpandCollapse = true;
}
page_load
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!Page.IsPostBack)
{
//Init values when the page is being loaded or accessed for the first time
initValues();
initLabels();
// this would bind the grid calling NeedDataSource
RadGrid1.Rebind();
}
}
RadGrid1_NeedDataSource
protected
void
RadGrid1_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
RadGrid1.DataSource = gridSource;
}
RadGrid1_ColumnCreated
protected
void
RadGrid1_ColumnCreated(
object
sender, Telerik.Web.UI.GridColumnCreatedEventArgs e)
{
GridBoundColumn boundColumn = e.Column
as
GridBoundColumn;
//Hide all columns, they will be made visible again later
if
(boundColumn !=
null
)
boundColumn.Visible =
false
;
}