View Single Post
  #5 (permalink)  
Old 06-06-2007, 01:26 PM
Honi Honi is offline
WMG Newcomer
 
Join Date: Jun 2007
Posts: 1
iTrader: (0)
Honi is on a distinguished road
Unhappy Export DataGrid data to excel

Hello
I used this procedure to generate an Excel file since three different functions. For two of these functions, the result is right. But for one of these functions each line of data is duplicated (two lines for each record).
Is there somebody who had this problem?
Do you have the idea of what could have involved this error?
How can I correct this?
Many thinks.



Quote:
Originally Posted by leodeveloper View Post
yes the following code wil helps you

private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

//Bind the DataGrid to DataSet

DataGridToExcel (DataGrid1, Response);

}

protected void DataGridToExcel(DataGrid dGridExport , HttpResponse httpResp)

{

httpResp.Clear();

httpResp.Charset = "";

httpResp.ContentType = "application/vnd.ms-excel";

StringWriter stringWrite = new StringWriter();

HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

DataGrid dGrid = new DataGrid();

dGrid = dGridExport;

dGrid.HeaderStyle.Font.Bold = true;

dGrid.DataBind();

dGrid.RenderControl(htmlWrite);

httpResp.Write(stringWrite.ToString());

httpResp.End();

}


Allah Bless on you
Reply With Quote
Sponsored Links
Register and sign in to hide this ad block