HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=Excel.xls");
Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.Charset ="";
HttpContext.Current.Response.ContentEncoding =System.Text.Encoding.Default;
Datagrid4.Page.EnableViewState =false;
System.IO.StringWriter tw = new System.IO.StringWriter() ;
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
Datagrid4.Visible=true;
Datagrid4.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();