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

[Solved] While exporting data to excel from telerik RadGrid column value replaces with zeros

1 Answer 34 Views
General Discussion
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Rashid
Top achievements
Rank 1
Rashid asked on 29 Jun 2015, 10:08 AM

I am using telerik RadGrid in which i am showing data like one column contain CARDNUMBERS like

 1234567894560900024

1234567894560900125

when i export this grid to excel the last three characters get replaced with zeros as shown below.

1234567894560900000

1234567894560900000

 

In the code behind data assigning code in shown below:

var cardNumber = gridRow.GetDataKeyValue("CARDNUMBER").ToString();

var lblCardNumber = (Label)e.Item.FindControl("lblCardNumber");

lblCardNumber.Text = cardNumber ;where CARDNUMBER is database column name. its datatype is varchar in the database.

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 02 Jul 2015, 07:51 AM
Hello Rashid,

The issue that you are facing will be replicated only with the Html export format and in order to define other format for that value you will need to use the approach from the following help article:
As you will notice, once you handle the server-side OnExportCellFormatting event you can get reference to the cells for the column holding the card number and apply the following:
protected void RadGrid1_ExportCellFormatting(object sender, ExportCellFormattingEventArgs e)
{
    if (e.FormattedColumn.UniqueName == "CardNumber")
    {
        e.Cell.Style["mso-number-format"] = @"\@";
    }
}

Hope this helps.


Regards,
Konstantin Dikov
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
General Discussion
Asked by
Rashid
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or