Formatting Columns while exporting Rad Grid View

2 posts, 0 answers
  1. saurabh
    saurabh avatar
    1 posts
    Member since:
    Sep 2014

    Posted 29 Sep 2014 Link to this post

    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..!!
  2. Boris
    Admin
    Boris avatar
    276 posts

    Posted 02 Oct 2014 Link to this post

    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.
     
  3. DevCraft banner
Back to Top