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
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
|