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

Export using dynamically created grid

2 Answers 197 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 19 Aug 2008, 03:21 PM
I have a page where I don't need a visual grid, but just want to programmatically create a RadGrid so I can use its export to ExcelML function.  I am getting "RadGrid must be databound before exporting."  I am calling DataBind(), so I really must be missing something simple here.  Any suggestions?


        protected void btnExport_Click(object sender, ImageClickEventArgs e) 
        { 
            DataTable dtExport = ExecTools.General.GetResCodeTreeExport(Application["ExecData"].ToString()); 
            Telerik.Web.UI.RadGrid ExportGrid = new RadGrid(); 
            ExportGrid.AutoGenerateColumns = true
            ExportGrid.DataSource = dtExport
            ExportGrid.DataBind(); 
            ExportGrid.ExportSettings.Excel.FileExtension = "xls"
            ExportGrid.ExportSettings.FileName = "ResCodes"
            ExportGrid.ExportSettings.ExportOnlyData = true
            ExportGrid.ExportSettings.IgnorePaging = false
            ExportGrid.ExportSettings.OpenInNewWindow = true
            ExportGrid.ExportSettings.Excel.Format = GridExcelExportFormat.ExcelML; 
            ExportGrid.MasterTableView.ExportToExcel(); 
        } 
 

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 20 Aug 2008, 08:08 AM
Hi Michael,

Instead of creating the Grid in the Export button click event. Create the Grid in the PageInit handler. Set the visibility of the Grid to true in the button click event.Also  bind the Grid in the NeedDataSourceEvent and see whether you are getting this error on exporting?
Go through the following help link to get more details on Programmatic Creation.
Programmatic creation

Shinu.
0
Michael
Top achievements
Rank 1
answered on 20 Aug 2008, 01:33 PM
Yeah, I was afraid that would be the response on this one.  I don't understand why it has to be part of the page lifecycle, and why it can't be used independently like you could with most other controls.  Thanks for the response anyway.

Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Michael
Top achievements
Rank 1
Share this question
or