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

2 posts, 0 answers
  1. Rashid
    Rashid avatar
    1 posts
    Member since:
    Jun 2015

    Posted 29 Jun 2015 Link to this post

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



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




    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.

  2. Konstantin Dikov
    Konstantin Dikov avatar
    1750 posts

    Posted 02 Jul 2015 Link to this post

    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.

    Konstantin Dikov
    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
  3. DevCraft R3 2016 release webinar banner
Back to Top