I need to create a grid entirely by code, assigning it some custom columns (GridTemplateColumn) and theses columns have HeaderTemplate, ItemTemplate and EditItemTerplate set with a custom class wich implements ITemplate.
I just followed this article : http://www.telerik.com/help/aspnet/grid/grdprogrammaticcreation.html
Each of my columns use an new instance of the same 'Itemplate class'
here is the content of InstanciateIn method into ItemTemplate class :
It is working fine !
But now, to be able to export this custom cxolumns in CSV format, I see here : http://www.telerik.com/help/aspnet-ajax/grid-csv-export.html that I need to Iterate throught each of my items , use FindControl to find my Literal, get content and assign it to my item Text property. Something like that :
OK, so I need to assign a ID to my Literal
Here is the new code of my item template :
My grid show up ok at first display, but at the first postback I got this error :
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Multiple controls with the same ID 'ctrlAcquis' were found. FindControl requires that controls have unique
How to set up unique id on all instance of my item template, but stay able to use FindControl("ctrlAcquis") ?
Do I need to name my control with the name of the custom colum for instance because each of my columns use the same Itemplate class ?
p.s: I'm using version 2010.1.519.35 of Telerik RadControls for ASP.NET Ajax
Thanks for help !
I just followed this article : http://www.telerik.com/help/aspnet/grid/grdprogrammaticcreation.html
Each of my columns use an new instance of the same 'Itemplate class'
here is the content of InstanciateIn method into ItemTemplate class :
public
void
InstantiateIn(Control container)
{
ctrlAcquis =
new
Literal();
ctrlAcquis.DataBinding +=
new
EventHandler(ctrl1_DataBinding);
Table tb =
new
Table();
TableRow r =
new
TableRow();
TableCell c1 =
new
TableCell();
TableCell c2 =
new
TableCell();
r.Cells.Add(c1);
r.Cells.Add(c2);
tb.Rows.Add(r);
c1.Controls.Add(ctrlAcquis);
container.Controls.Add(tb);
}
It is working fine !
But now, to be able to export this custom cxolumns in CSV format, I see here : http://www.telerik.com/help/aspnet-ajax/grid-csv-export.html that I need to Iterate throught each of my items , use FindControl to find my Literal, get content and assign it to my item Text property. Something like that :
foreach
(GridDataItem item
in
RadGrid1.MasterTableView.Items)
{
Image img = item[
"MyColumn"
].FindControl(
"Image1"
)
as
Image;
item[
"MyColumn"
].Text = img.AlternateText;
}
OK, so I need to assign a ID to my Literal
ctrlAcquis
Here is the new code of my item template :
public
void
InstantiateIn(Control container)
{
ctrlAcquis =
new
Literal();
ctrlAcquis.ID =
"ctrlAcquis"
;
ctrlAcquis.DataBinding +=
new
EventHandler(ctrl1_DataBinding);
Table tb =
new
Table();
TableRow r =
new
TableRow();
TableCell c1 =
new
TableCell();
TableCell c2 =
new
TableCell();
r.Cells.Add(c1);
r.Cells.Add(c2);
tb.Rows.Add(r);
c1.Controls.Add(ctrlAcquis);
container.Controls.Add(tb);
}
My grid show up ok at first display, but at the first postback I got this error :
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Multiple controls with the same ID 'ctrlAcquis' were found. FindControl requires that controls have unique
How to set up unique id on all instance of my item template, but stay able to use FindControl("ctrlAcquis") ?
Do I need to name my control with the name of the custom colum for instance because each of my columns use the same Itemplate class ?
p.s: I'm using version 2010.1.519.35 of Telerik RadControls for ASP.NET Ajax
Thanks for help !