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

DateTime format issue with export to csv

3 Answers 690 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Prava kafle
Top achievements
Rank 1
Prava kafle asked on 16 Jan 2013, 04:20 PM
Hi,
Export to csv modifies datetime data. DateTime column in my grid has data in following format""11/11/2011 1:50:51 PM
but after export it is modified to "11/11/2011 13:50:51".

How can I persist data on exporting/ modify it during  this event. I tried to use  "ExportCellFormatting" but it never fired for csv export.

Thanks,
Prava

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Jan 2013, 04:29 AM
Hi,

Try the following code to achieve your scenario.
C#:
protected void RadGrid1_ExportCellFormatting(object sender, ExportCellFormattingEventArgs e)
{
    if ((e.FormattedColumn.UniqueName) == "BirthDate")
    {
        e.Cell.Style["mso-number-format"] = @"dd.MM.yyyy hh:mm:ss";
    }
}

Thanks,
Shinu
0
Prava kafle
Top achievements
Rank 1
answered on 17 Jan 2013, 04:10 PM
Hi Shinu,

Yes, I had tried that event  handler  but the problem is that event never gets fired on clicking "Export to CSV".
What configuration do I need to fire that event in a  dynamic Grid .


               RadGrid  radGrid = new RadGrid();
                radGrid.ID = tableName;
                GridColumnManager gridManager = new GridColumnManager();
                gridManager.CheckDFMBeforeAddingColumnsToGrid(radGrid, tableName);
                
                radGrid.PageSize = 10;
                radGrid.MasterTableView.AllowPaging = true;
                radGrid.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
                
                radGrid.MasterTableView.DataKeyNames = new string[] { "ID" };
                radGrid.MasterTableView.ClientDataKeyNames = new string[] { "ID" };
                radGrid.AllowMultiRowSelection = false;
                radGrid.AllowMultiRowEdit = false;
                radGrid.MasterTableView.TableLayout = GridTableLayout.Auto;
 radGrid.ExportCellFormatting += new EventHandler<ExportCellFormattingEventArgs>(radGrid_ExportCellFormatting);






 void radGrid_ExportCellFormatting(object sender, ExportCellFormattingEventArgs e)
        {
           string typestr=e.FormattedColumn.UniqueName.GetType().ToString();
            if (e.FormattedColumn.UniqueName == "TimeOpened")
                   e.Cell.Style["mso-number-format"] = @"m\/d\/yy\ h\:mm\:ss\ AM\/PM";
              
        }



Thanks,
Prava
0
Kostadin
Telerik team
answered on 22 Jan 2013, 02:54 PM
Hi Prava,

Note that CSV export format is based on a plain text and you could not format it as you may format Excel or Word. In your case the DateTime column is formatted by the program itself (for instance Excel). If you open the csv file with a simple text editor (for instance Notepad) you will see that the DateTime column has exactly the same format as the one in the grid.

Kind regards,
Kostadin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Prava kafle
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Prava kafle
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or