datagrid|excel| data if (datagrid1.items.count==0)
{
Response.Write ("<script>alert (' Sorry, you did not query to any records, cannot export data ') </script>");
}
Else
{
Response.Clear ();
Response.buffer= true;
Response.charset= "GB2312";
Response.appendheader ("Content-disposition", "Attachment;filename=filename.xls");
Response.contentencoding=system.text.encoding.getencoding ("GB2312");
Set the output stream to Simplified Chinese
Response.ContentType = "Application/ms-excel";
Sets the output file type to be an Excel file.
This. EnableViewState = false;
System.Globalization.CultureInfo Mycitrad = new System.Globalization.CultureInfo ("ZH-CN", true);
System.IO.StringWriter ostringwriter = new System.IO.StringWriter (Mycitrad);
System.Web.UI.HtmlTextWriter ohtmltextwriter = new System.Web.UI.HtmlTextWriter (ostringwriter);
Datagrid1.rendercontrol (Ohtmltextwriter);
Response.Write (Ostringwriter.tostring ());
Response.End ();
}