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

Formatting Columns while exporting Rad Grid View

1 Answer 39 Views
GridView
This is a migrated thread and some comments may be shown as answers.
saurabh
Top achievements
Rank 1
saurabh asked on 29 Sep 2014, 06:40 PM
We are using a telerik Rad Gridview in our Silverlight Project. It have few fixed columns and few other dynamic. Number of dynamic column depend on the data.
We want to format specific columns while Exporting the gridview to excel.
Please find the attached image and code for more details of the issue and code we are using for this....

Our main concern is how to detect column header/column name of a particular cell in the element_exporting event. Something like this;;;;;
if(e.Element == ExportElement.Cell)
{
if(column.Header.ToString() == "My String Column")
{
e.Value = string.Format(@"=T(""{0}"")", e.Value);
}


Here we are not able to get the column object. If we get the column name then we can control the formatting inside the code. 
Thanks for the help in advance..!!

1 Answer, 1 is accepted

Sort by
0
Boris
Telerik team
answered on 02 Oct 2014, 11:22 AM
Hello Saurabh,

A possible way to fulfill your goal is to modify your if statement to include the e.Context property of the GridViewElementExportingEventArgs. By doing so you can specify the UniqueName of the column you need to target, like so:

private void clubsGrid_ElementExporting(object sender, GridViewElementExportingEventArgs e)
{
    if (e.Element == ExportElement.Cell && (e.Context as GridViewDataColumn).UniqueName == "Name")
    {
        var column = e.Context as GridViewDataColumn;
        // Do something
    }
}

I hope this helps.

Regards,
Boris Penev
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
saurabh
Top achievements
Rank 1
Answers by
Boris
Telerik team
Share this question
or