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

Export grid created programmicly

4 Answers 99 Views
Grid
This is a migrated thread and some comments may be shown as answers.
thomas
Top achievements
Rank 1
thomas asked on 27 Aug 2008, 02:41 PM
I have a  webpage that has  an Asp.Net ListView control that looks like a table.  I would like to export it to  an Excel file.  I 'm trying to use the radGrid to do so by creating it in the code behind and placing it in a placeholder on the aspx page.  I do not get any errors but my grid has no columns or rows, even though it showes as being databound.  Any help would be appreciated.  Here is my code for my button click to create radGrid.

            RadGrid grid = new RadGrid();
            grid.ID = "RadGrid1";

            this.phExport.Controls.Add(grid);

            grid.AutoGenerateColumns = true;  //added for testing
            grid.DataSource = FAM.ContactManager.Domain.Contact.GetExportData("2008","1");  //just returns a datatable
            grid.Rebind();

            grid.MasterTableView.ExportToExcel();

4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 27 Aug 2008, 03:54 PM
Hello Thomas,

Please take a look at the demo I created for you. You can find it attached to this post.

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
thomas
Top achievements
Rank 1
answered on 27 Aug 2008, 05:05 PM
Daniel,
thanks for the response but it is behaving the same way where  there is no error thrown when debugging and I can see that the radgrid datasource has the correct values but no columns or rows are produced and no export happens.  I have modified my code to almost match that of yours with no results.  Is there something i'm missing?

        protected void lbtnExport_Click(object sender, EventArgs e)
        {
            RadGrid radGrid1 = new RadGrid();
            radGrid1.ID = "RadGrid1";
            radGrid1.NeedDataSource += new GridNeedDataSourceEventHandler(radGrid1_NeedDataSource);
            this.phExport.Controls.Add(radGrid1);
            radGrid1.Rebind();

            radGrid1.MasterTableView.ExportToExcel();

        }

        void radGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            (source as RadGrid).DataSource = FAM.ContactManager.Domain.Contact.GetExportData("2008", "1");
        }

thanks,
tom
0
thomas
Top achievements
Rank 1
answered on 27 Aug 2008, 05:31 PM
Daniel,
I have come a little further with the issue and I apologize for not getting you all the information that would help you help me. 

so here is the additional information:
I have two  dropdowns that are cascading.  The post back from the second dropdown fires to populate the listview which is within a updatepanel.  The button that was to fire the export is in the footer of the listview.  I have a feeling that since the listview is not doing a postback it is effecting the outcome.  When i put the code for the export into the dropdown all works okay since it is doing a full postback. 


So the problem seems to be with the button being inside a listview wrapped by a updatepanel.  Hope this additional information helps in  your much appreciated assistance.

tom
0
Accepted
Daniel
Telerik team
answered on 01 Sep 2008, 07:47 AM
Hello Thomas,

Please try put the following code under your Page Load event handler:
ScriptManager.GetCurrent(Page).RegisterPostBackControl(lbtnExport); 
 

This will help you register your control as postback trigger instead of asynchronous.

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
thomas
Top achievements
Rank 1
Answers by
Daniel
Telerik team
thomas
Top achievements
Rank 1
Share this question
or