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

[Solved] Exporting Grid without declarative datasource?

2 Answers 109 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 01 Oct 2009, 01:38 PM
I am struggling with the Grid Export functionality.

To investigate, I took the export demo on my machine, checked that it worked fine.
Removed all excel formatting, checked that it worked fine.


Then, I removed the declarative section of the Grid DataSource and replaced that by a PopulateGrid() function in both the Page_Load and Button4_Click
        <telerik:RadGrid ID="RadGrid1" AllowSorting="True" 
            AllowPaging="True" PageSize="10" runat="server" GridLines="None" 
            Width="95%" > 
            <MasterTableView Width="100%"></MasterTableView> 
        </telerik:RadGrid> 

        protected void Button4_Click(object sender, System.EventArgs e)  
        {  
            PopulateGrid();  
 
            ConfigureExport();  
            RadGrid1.ExportSettings.Excel.Format = Web.UI.GridExcelExportFormat.ExcelML;  
            CheckBox1.Checked = true;  
            RadGrid1.ExportSettings.ExportOnlyData = true;              
            RadGrid1.MasterTableView.ExportToExcel();              
        }  
 
        void PopulateGrid()  
        {  
            SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);  
            SqlCommand cmd = new SqlCommand("SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, PostalCode FROM Customers", conn);  
              
            conn.Open();  
            SqlDataReader reader = cmd.ExecuteReader();  
            RadGrid1.DataSource = reader;  
            RadGrid1.DataBind();  
 
        } 
At this stage, the demo still works BUT the file exported is empty.

Is there a reason why populating the grid "on the fly" would not work with the export to excel functionality?

Many Thanks

Eric

2 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 01 Oct 2009, 04:41 PM
Hello Eric,

Please note that ExcelML engine fetches the data directly from your datasource. In your scenario, RadGrid can't access the necessary data. To avoid this behavior you can use advanced data binding with NeedDataSource.
Advanced Data-binding

Let me know if you need more information.

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Eric
Top achievements
Rank 1
answered on 01 Oct 2009, 04:43 PM
Seems to make sense with what I have seen...
Will give that a shot
Tags
Grid
Asked by
Eric
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Eric
Top achievements
Rank 1
Share this question
or