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

[Solved] Exporting programatically created grid

7 Answers 301 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 16 Jun 2008, 03:06 AM
I'm adding a programatically created grid to a place holder - is it possible to export this grid (as a PDF or excel sheet)? Nothing I try seems to work, I've also tried recreating the grid and exporting that on a button click but I get an error stating 'RadGrid must be databound before exporting'.

7 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Jun 2008, 04:49 AM
Hi,

Go through the following demo links.

MS Excel/MS Word/CSV
Export to PDF

Princy.
0
Josh
Top achievements
Rank 1
answered on 16 Jun 2008, 05:54 AM
Those examples haven't really helped (had already looked at them), I have the grid in a place holder which itself is in a radajaxpanel. I have also seen the examples on how to cancel the partial post back for the buttons which trigger the export but didn't have much luck with that either. When I try to get the radgrid control from the place holder I always get an exception as the place holder shows up as having 0 controls....

Since I can easily recreate the grid in the code-behind I was wondering if I could just re-generate it there and export that. I get the error I mentioned below when I do that though (radgrid must be databoud before exporting) even though there is definitely data in the grid (checked via breakpoint).

I basically have:

protected void ExportToPDFButton(object sender, EventArgs e)
{
    RadGrid newGrid = same function that generates the grid for the place holder...;
    newGrid.ExportToPdf();
}

and get the error on the export to PDF method. Any suggestions? I'd really like to accomplish this without doing a full postback since I really don't need the instance of the grid on the actual page but if that's only way I'm open to suggestions.
0
Vlad
Telerik team
answered on 16 Jun 2008, 07:47 AM
Hello Josh,

Can you verify if the grid is bound? Are you using NeedDataSource?

All the best,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Shinu
Top achievements
Rank 2
answered on 16 Jun 2008, 08:05 AM
Hi Josh,

Go through the following demo link to get more information about using AdvanceDataBinding techniques.
Advanced data-binding

Shinu.
0
Josh
Top achievements
Rank 1
answered on 16 Jun 2008, 07:09 PM
I;' not sure I'm clear on how to check if the grid is bound. The appropriate data is there (rows and columns), checking via breakpoint before calling ExportToPdf(). I am not using NeedDataSource (not sure how to add this programmatcially) and I don't see why I need to since I'm recreating the entire grid in my ExportToPDFButton event handler...

There are lots of demos explaining how to do things when the grid is defined in the aspx page and plenty on how to create a grid programmatically and added to a place holder yet there doesn't appear to be much on how to handle grids that have been created programmatically... Having alot of issues using the latter type of grid for anything besides displaying data...
0
Accepted
Daniel
Telerik team
answered on 18 Jun 2008, 05:26 AM
Hi Josh,

I tried to reproduce your issue but I am unable to see any unusual behavior. Thus I made an example website for you. It would be helpful if you give me feedback whether this helps.

Sincerely yours,
Daniel
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Josh
Top achievements
Rank 1
answered on 19 Jun 2008, 04:36 AM
Thanks! It wasn't clear to me that I had to replace the control on the page in order for it to be databound, that's what I was missing...
Tags
Grid
Asked by
Josh
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Josh
Top achievements
Rank 1
Vlad
Telerik team
Shinu
Top achievements
Rank 2
Daniel
Telerik team
Share this question
or