Hi,
I'm trying to create a gridview with multiple columns that can contain different kinds of System.Web.UI.Controls in Code-Behind. One of them is a radComboBox.
When I add the radComboBox performance drops down dramatically, but I can't find the exact problem.
Is there something I am doing wrong, or is this a known issue?
Below is the Code-Behind file:
Thanks,
Klaas
I'm trying to create a gridview with multiple columns that can contain different kinds of System.Web.UI.Controls in Code-Behind. One of them is a radComboBox.
When I add the radComboBox performance drops down dramatically, but I can't find the exact problem.
Is there something I am doing wrong, or is this a known issue?
Below is the Code-Behind file:
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
Telerik.Web.UI;
using
System.ComponentModel;
using
System.Collections;
using
System.Collections.Specialized;
namespace
WebApplication1
{
// Default Page
public
partial
class
_Default : System.Web.UI.Page
{
protected
override
void
OnInit(EventArgs e)
{
base
.OnInit(e);
if
(IsPostBack)
createStaticControls();
}
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
createStaticControls();
}
private
void
createStaticControls()
{
int
index = 0;
GridViewExtension gridView =
new
GridViewExtension();
gridView.EnableInsert =
true
;
gridView.rowSize = 20;
Panel1.Controls.Add(gridView);
while
(index != 5)
{
TemplateField tfield =
new
TemplateField();
tfield.Visible =
true
;
tfield.ItemTemplate =
new
DynamicControl(index);
tfield.HeaderText = index.ToString();
gridView.Columns.Add(tfield);
index++;
}
gridView.DataBind();
Button b =
new
Button();
Panel1.Controls.Add(b);
}
}
// Control - ITemplate, now always an RadComboBox
public
class
DynamicControl : ITemplate
{
private
int
index;
public
DynamicControl(
int
_index)
{
index = _index;
}
public
void
InstantiateIn(System.Web.UI.Control container)
{
RadComboBox realControl =
new
RadComboBox();
//Label realControl = new Label(); // Label much faster
realControl.Enabled =
true
;
realControl.Visible =
true
;
realControl.ID = index.ToString();
realControl.Text = index.ToString();
container.Controls.Add(realControl);
}
}
// GridView Extension, make empty rows with staticControls
public
class
GridViewExtension : System.Web.UI.WebControls.GridView
{
public
int
rowSize;
public
bool
EnableInsert;
// Override the creation of childControls to create empty rows
protected
override
int
CreateChildControls(System.Collections.IEnumerable dataSource,
bool
dataBinding)
{
//create table
Table table =
new
Table();
table.ID =
this
.ID;
//create a new header row
GridViewRow row =
base
.CreateRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal);
//convert the exisiting columns into an array and initialize
DataControlField[] fields =
new
DataControlField[
this
.Columns.Count];
this
.Columns.CopyTo(fields, 0);
this
.InitializeRow(row, fields);
table.Rows.Add(row);
this
.Controls.Add(table);
while
(rowSize != 0)
{
this
.CreateInsertRow(rowSize,
false
);
rowSize--;
}
return
0;
}
protected
virtual
void
CreateInsertRow(
int
rowIndex,
bool
allowPaging)
{
GridViewRow row =
this
.CreateRow(rowIndex, -1, DataControlRowType.DataRow, DataControlRowState.Insert);
row.ID = rowIndex.ToString();
DataControlField[] fields =
new
DataControlField[
this
.Columns.Count];
this
.Columns.CopyTo(fields, 0);
if
(
this
.HasControls())
{
int
index = ((Table)
this
.Controls[0]).Rows.Count - (
this
.ShowFooter ? 1 : 0) - (allowPaging ? 1 : 0);
((Table)
this
.Controls[0]).Rows.AddAt(index, row);
}
this
.InitializeRow(row, fields);
}
}
}
Thanks,
Klaas