I need to export an Excel table from the gridview. The following is the export code.
Public static void datagridtoexcel (gridview DG, page)
{
Page. response. Clear ();
Page. response. Buffer = true;
Page. response. charset = "gb2312 ";
String STR = "generated spreadsheet .xls ";
Page. response. appendheader ("content-disposition", "attachment; filename =" + httputility. urlencode (STR, encoding. utf8 ));
Page. response. contentencoding = encoding. getencoding ("gb2312 ");
Page. response. contenttype = "application/MS-excel ";
Page. enableviewstate = false;
Cultureinfo formatprovider = new cultureinfo ("ZH-CN", true );
Stringwriter writer = new stringwriter (formatprovider );
Htmltextwriter writer2 = new htmltextwriter (writer );
DG. rendercontrol (writer2 );
Page. response. Write (writer. tostring ());
Page. response. End ();
DG. allowpaging = true;
DG. databind ();
}
On the normal page, everything is normal and the Excel file can be exported normally.
When this page is added to the Ajax framework and the scriptmanager control and updatepanel control are used, the page displays response-related errors,
Please advise me how to solve the conflict between scriptmanager and page output!