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

RadGrid and Exporting to CSV

1 Answer 251 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 26 Jul 2011, 07:06 PM
Telerik,

I would like to export all data from my radgrid using CSV but its not working as expected.


I have added a CommandItemSettings tag for using the CSV export button on the Grid. When I click the button to export my current grid, the ItemCommand event is raised and I test for the following condition and my code is as follows:

protected void myGrid_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.ExportToCsvCommandName)
    {
        IsExport = true;
        myGrid.ExportSettings.IgnorePaging = false;
        myGrid.MasterTableView.GetColumn("Activities").Visible = false;
        myGrid.MasterTableView.GetColumn("License").Visible = false;
        myGrid.MasterTableView.GetColumn("Delete").Visible = false;
        myGrid.MasterTableView.AllowPaging = false;           
    }  
}

Setting the following property, allows me to export just the one page, but by changing this value to true, I only export the Header Row!?
myGrid.ExportSettings.IgnorePaging = false;

 I also have an ItemDataBound event that is called where I format a TableCell's text property to be equal to that of a HiddenField inside of a TemplateColumn.

bool IsExport = false;
protected void myGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
    //Fix TemplateColumn on Exporting
    if (IsExport && e.Item is GridEditableItem)
    {
        //Fix Template Column Text           
        GridEditableItem item = e.Item as GridEditableItem;
        foreach (TableCell cell in item.Cells)
        {
            HiddenField field= (HiddenField)e.Item.FindControl("hdnField");
            if (field != null)
            {
                cell.Text = field.Value;
            }
        }
    }        
}

How can I export all the data in my grid to CSV?? So far I have only been able to export it for the first page. I need the option to export it for all pages.

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 01 Aug 2011, 02:49 PM
Hello Steve,

You have to rebind RadGrid after executing this code:
myGrid.MasterTableView.AllowPaging = false;

By the way, how do you bind RadGrid? Which approach do you use - simple data-binding, advanced data-binding or a datasource control?

Best regards,
Daniel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Steve
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or