I have a couple of questions about exporting a grid as CSV.
- All columns appear to be exported as strings (i.e. surrounded by quote-marks) - is this by design, or can I control this?
- I have AutoGeneratedColumns that are hidden initially, i've tried to set them to Visible, but yet they do not appear in the exported csv file?
- My grid only loads 1 page of information at a time, I'd like to export ALL pages. Now I can call my stored procedure and tell it to fetch all data rather than just a single page, i've tried reassigning the DataSource & issuing a DataBind() prior to executing the ExportToCSV(), but still only 1 page of information is shown -- how can I refresh the datasource prior to export?
thanks
Brian.
4 Answers, 1 is accepted
0
Brian
Top achievements
Rank 1
answered on 18 Feb 2010, 04:51 PM
To help, here is the code that i'm currently executing:
| protected void ExportToCSV_Click(object sender, EventArgs e) |
| { |
| PrepareGridForExport(); |
| m_dgCustomerCalls.MasterTableView.ExportToCSV(); |
| ShowCallHistory(); |
| } |
| protected void PrepareGridForExport() |
| { |
| m_dgCustomerCalls.PageSize = 1000000; |
| UpdateDataGrid(false, DateFrom, DateTo, m_dgCustomerCalls.PageSize, CallScenarioFilter, CallDirectionalityFilter); |
| m_dgCustomerCalls.MasterTableView.Columns.FindByUniqueName("CallTrace").Visible = false; |
| m_dgCustomerCalls.MasterTableView.Columns.FindByUniqueName("Info").Visible = false; |
| m_dgCustomerCalls.MasterTableView.Columns.FindByUniqueName("TemplateColumn").Visible = false; |
| m_dgCustomerCalls.MasterTableView.Columns.FindByUniqueName("Malformed").Visible = false; |
| foreach (GridColumn col in m_dgCustomerCalls.MasterTableView.AutoGeneratedColumns) |
| { |
| if (col.UniqueName == "CallFrom" || col.UniqueName == "CallTo") |
| col.Visible = true; |
| } |
| m_dgCustomerCalls.DataBind(); |
| } |
The UpdateDataGrid() method, essentially calls upon the Stored Procedure, fetches the appropriate data, and assigns the grid's datasource. I've traced this through, and i'm getting 199 rows returned from the SP.
The ShowCallHistory() after the export, essentially resets the grid back to what it was like prior to the export.
0
Hello Brian,
Straight onto your questions:
1. Yes, as mentioned in our documentation, this is the default behavior.
CSV export help topic
2. You don't have to reset the initial state of your columns. All these changes will affect the exported file only. Please comment out this line and try again:
3. If the above suggestion doesn't help, please post the contents of the ShowCallHistory method here.
Best regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Straight onto your questions:
1. Yes, as mentioned in our documentation, this is the default behavior.
CSV export help topic
2. You don't have to reset the initial state of your columns. All these changes will affect the exported file only. Please comment out this line and try again:
protected void ExportToCSV_Click(object sender, EventArgs e) { PrepareGridForExport(); m_dgCustomerCalls.MasterTableView.ExportToCSV(); //ShowCallHistory(); }3. If the above suggestion doesn't help, please post the contents of the ShowCallHistory method here.
Best regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Brian
Top achievements
Rank 1
answered on 19 Feb 2010, 09:31 AM
Daniel,
Thankyou for your response. I have commented out the call to ShowCallHistory(), and now on export I do get ALL the data - which is great.
However, the two auto-generated columns CallFrom & CallTo still do not appear on the export? Just for information the two autogenerated columns are hidden from view as there is another column (with the unique (but rather ambiguous) name of 'TemplateColumn') - this column combines the CallFrom/To column values and wraps a whole lot of markup around them to pretty it up for display.
So when we come to the export, the intention is to hide the 'TemplateColumn' and show the CallFrom / CallTo columns (which both sit in the AutoGeneratedColumns collection - however these two columns are absent from the export?
Brian
0
Hello Brian,
I created a sample project for you. Please test it locally and let me know whether this helps.
Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
I created a sample project for you. Please test it locally and let me know whether this helps.
Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.