Link to home
Start Free TrialLog in
Avatar of AvinashKN
AvinashKN

asked on

Error while exporting to Excel with Gridview

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();
        PopulateGrid();
        gTempViewForExcelExport.DataSource = m_dsContractorData;
        gTempViewForExcelExport.AllowPaging = false;
        gTempViewForExcelExport.DataBind();
 
        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

ASKER CERTIFIED SOLUTION
Avatar of aherps
aherps
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bob Learned
Wow, pointing to an article that the asker asked in a different forum--what are the odds *BIG GRIN*.
Sorry - my bad - I didn't look at the usernames!
Avatar of AvinashKN
AvinashKN

ASKER

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