Dear All!
I have a big problem with the GridTemplateColumn. I've created grid in the PageInit at code-behind. Everything works fine except one thing.
I have a Template Column with different running number. Means every time I need to create different pieces of (Template) Columns. At first 5 pieces, after a button postback 2 pieces (depends on _numberOfMD), etc. :
protected void Page_Init(object sender, EventArgs e)
{
RadGrid _grdEval = new RadGrid();
....
for (int i = 0; i < _numberOfMD; i++)
{
GridTemplateColumn tmplColumn = new GridTemplateColumn();
tmplColumn.HeaderText = "ESY<BR />OK";
tmplColumn.UniqueName = "EasyChkTempColumn" + i.ToString();
tmplColumn.ItemTemplate = new MDTemplate("MD");
tmplColumn.AllowFiltering = false;
this._grdEval.Columns.Add(tmplColumn);
}
}
But the error: At the first load (not postback) five columns created successfully and after postback (with button press) if I want to create only 2 columns (the _numberOfMD will be 2 instead of 5), the following exception thrown:
Index was out of range. Must be non-negative and less than the size of the collection.
Description: An
unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the
error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
How can I do that every time with different _numberOfMD the Grid works well without exception and create and bind number of columns as I want.
thanks
I have a big problem with the GridTemplateColumn. I've created grid in the PageInit at code-behind. Everything works fine except one thing.
I have a Template Column with different running number. Means every time I need to create different pieces of (Template) Columns. At first 5 pieces, after a button postback 2 pieces (depends on _numberOfMD), etc. :
protected void Page_Init(object sender, EventArgs e)
{
RadGrid _grdEval = new RadGrid();
....
for (int i = 0; i < _numberOfMD; i++)
{
GridTemplateColumn tmplColumn = new GridTemplateColumn();
tmplColumn.HeaderText = "ESY<BR />OK";
tmplColumn.UniqueName = "EasyChkTempColumn" + i.ToString();
tmplColumn.ItemTemplate = new MDTemplate("MD");
tmplColumn.AllowFiltering = false;
this._grdEval.Columns.Add(tmplColumn);
}
}
But the error: At the first load (not postback) five columns created successfully and after postback (with button press) if I want to create only 2 columns (the _numberOfMD will be 2 instead of 5), the following exception thrown:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Description: An
unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the
error and where it originated in the code. Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
How can I do that every time with different _numberOfMD the Grid works well without exception and create and bind number of columns as I want.
thanks