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

[Solved] Problems in exporting radgrid to word and excel files

1 Answer 130 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Carlos Marchi
Top achievements
Rank 1
Carlos Marchi asked on 17 Sep 2009, 02:24 PM
Hi Everybody,

I have been find a solution but until now I dint solve the problem. I'm going to explain about it.

There is a .aspx page where there is a radgrid. There are also two buttons - word button and excel button.
When the user clicks on word button for example it is invoked its event:

protected

 

void btnExportWord_Click(object sender, System.Web.UI.ImageClickEventArgs e)

 

{

 

    RadGrid radGrid = this.getData();

 

 

    this.ConfigureExportation(radGrid);

 

    radGrid.MasterTableView.ExportToWord();

}

How you can see, I create a new radgrid where it is filled out by getData method. I created a new radgrid because on page, the radgrid has jus some columns and I'd like to export all columns from table to word or excel file.

See the getData() Method:

 

private

 

RadGrid getData()

 

{

 

    RadGrid radGrid = new RadGrid();

 

    radGrid.DataSource = gobjBLProduct.List(

this.Company, this.txtSearch.Text.Trim());

 

    radGrid.DataBind();

 

 

    return radGrid;

 

}

Now, See ConfigureExportatio() Method:

 

private

 

void ConfigureExportation(RadGrid pradGrid)

 

{

    pradGrid.ExportSettings.ExportOnlyData =

true;

 

    pradGrid.ExportSettings.IgnorePaging =

true;

 

    pradGrid.ExportSettings.OpenInNewWindow =

true;

 

    pradGrid.ExportSettings.FileName =

"List of Product - " + DateTime.Now.ToShortDateString();

 

}

The problem is when I click on word button there is an exception where it is showed this message: "RadGrid must be DataBound" before exporting."

I didnt undertand why this error. What mistake did i do?

Can anybody help me, please?

Thank you for attention,

Carlos

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 23 Sep 2009, 01:31 PM
Hello Carlos,

First, you should add RadGrid to controls' collection of some placeholder because it should be rendered on the page. Second - you can't use simple data-binding in this scenario since IgnorePaging will invoke RadGrid.Rebind to fetch all data from your datasource.

Please examine the following link:
Advanced Data-binding

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.
Tags
General Discussions
Asked by
Carlos Marchi
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or