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

Changing item values on itemdatabound and again for export

1 Answer 117 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 27 Apr 2010, 01:56 AM
Hi,
I am have a column that is bound to a string in the form comma separated list.

I want to display the list items on separate lines in the cell so I use the following

    protected void grvReport_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = ((GridDataItem)e.Item); 
            item["coltrainerList"].Text = item["coltrainerList"].Text.Replace(",""<br/>"); 
        } 
 
        // More unrelated stuff 
    } 

This works as expected. But I also want to use the ExportToCSV() feature using a linkbutton to trigger the export. I don't want <br/>s OR commas to appear in my exported CSV file so I attempt to change the data again prior to calling export as follows...
foreach (GridDataItem item in grvReport.MasterTableView.Items) 
   item["coltrainerList"]. Text = item["coltrainerList"].Text.Replace("<br/>"" - "); 
 
grvReport.MasterTableView.ExportToCSV(); 
 

This does the expected change, but unfortunately the data gets bound again before it is actually exported so I get the initial comma separated data which in turn gets changed to include the <br/>s. Therefore I still get the <br/>s in my CSV file.

Is there any way to stop the grid from rebinding when the export function is called? Or can you suggest some other way of achieving the desired effect?

Cheers


1 Answer, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 27 Apr 2010, 09:01 PM
Hello Lourein,

I suggest you try to modify the output directly - you can use the GridExporting event for that purpose:
protected void RadGrid1_GridExporting(object source, GridExportingArgs e)
{
    if (e.ExportType == ExportType.Csv)
    {
        e.ExportOutput = e.ExportOutput.Replace("something", "something else");
    }
}

I hope this helps.

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