This is a migrated thread and some comments may be shown as answers.

RadGrid must be databound before exporting.

2 Answers 563 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Juan Luis
Top achievements
Rank 1
Juan Luis asked on 29 Jun 2010, 09:00 AM
Hi, i have this code and I dont know how to resolve the exception. The action is executed when i press a button btnExportar

protected

 

 

void BtnExportar_Click(object sender, EventArgs e)

 

 

{

 

 

 

 

List<Festivo> listaFestivos = ....

 

//se crea un RadGrid vinculado a la lista de festivos.

 

RadGrid rg = new RadGrid();

 

//configuramos el radGrid para que tenga una sola columna

 

GridBoundColumn columnaFestivos = new GridBoundColumn();

columnaFestivos.UniqueName =

 

"Festivos";

 

 

columnaFestivos.DataField = 

 

"Fecha";

 

 

columnaFestivos.HeaderText = 

 

"Festivos";

 

 

rg.MasterTableView.Columns.Add(columnaFestivos);

rg.DataSource = listaFestivos;

rg.DataBind();

 

 

 

this.Exportar(rg);

}

 

 

 

private void ConfigureExport(RadGrid rg)

{

rg.ExportSettings.ExportOnlyData =

 

true;

 

 

rg.ExportSettings.HideStructureColumns = 

 

true;

 

 

rg.ExportSettings.IgnorePaging =

 

true;

 

 

rg.ExportSettings.OpenInNewWindow = 

 

true;

 

 

rg.Columns[0].Visible = 

 

false;

 

 

}

 

 

 

 

public void Exportar(RadGrid rg)

{

ConfigureExport(rg);

rg.MasterTableView.ExportToExcel();

}

can you help me? thanks

 

2 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 02 Jul 2010, 12:41 PM
Hello Juan,

You should add RadGrid to Page's controls collection before exporting it. Note that this won't affect your page but only the exported file.

Best regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Mihir
Top achievements
Rank 1
answered on 01 Jul 2013, 12:32 PM
Hi Daniel,

Thanks for the suggestion.. this solve my problem..

just need to add
 
Page.Controls.Add(your control name); in your code (aspx.cs) page.

Thanks,
Mihir
Tags
Grid
Asked by
Juan Luis
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Mihir
Top achievements
Rank 1
Share this question
or