Error while exporting to Excel with Gridview

Posted on 2008-11-10
Last Modified: 2013-11-07
Hello all,

I'm getting some errors while exporting the data in my gridview to excel. I have a column called account number which is not showing properly in Excel.

For example, the account number 9001022199001 is showing up as 9.00103E+12. But when I click on the field in Excel, it shows up correctly. I think its a formatting error in Excel but I'm not sure if the problem is Excel or my code.  

How can I fix this problem?
protected void Button1_Click(object sender, EventArgs e)


        GridView gTempViewForExcelExport = new GridView();


        gTempViewForExcelExport.DataSource = m_dsContractorData;

        gTempViewForExcelExport.AllowPaging = false;



        GridViewExportToExcel.Export("BulkExtract.xls", gTempViewForExcelExport);



    protected void gvUsers_RowDataBound(object sender, GridViewRowEventArgs e)



        if (((GridViewRowEventArgs)e).Row.RowType == DataControlRowType.DataRow)


            ((GridViewRowEventArgs)e).Row.Cells[1].Attributes.Add("class", "text");



Open in new window

Question by:AvinashKN
    LVL 7

    Accepted Solution

    Discussed here:

    The code snippets there look to be what you're after
    LVL 96

    Expert Comment

    by:Bob Learned
    Wow, pointing to an article that the asker asked in a different forum--what are the odds *BIG GRIN*.
    LVL 7

    Expert Comment

    Sorry - my bad - I didn't look at the usernames!

    Author Comment

    Haha, It's ok. I obviously figured out what to do. Thanks.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now