How to export datagrid to excel,note pad,PDF using Asp.Net?
you can export datagrid to word,excel using httpresponce object and string builder/string.
here is the following code to expost datagrid to word.
u can change type to .xls from .doc to export to excel.
i tried to export to pdt, but it didn't works fine.
-----------
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=Yearwise Yield and Expenses.doc");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.word";
System.IO.StringWriter stringWrite =
System.Web.UI.HtmlTextWriter htmlWrite =
DataGrid1.ForeColor=Color.Black;
DataGrid1.HeaderStyle.BackColor=Color.White;
DataGrid1.HeaderStyle.Font.Bold=
DataGrid1.HeaderStyle.Font.Size=11;
DataGrid1.ItemStyle.ForeColor=Color.Black;
DataGrid1.ItemStyle.Font.Size=11;
DataGrid1.ItemStyle.VerticalAlign=System.Web.UI.WebControls.VerticalAlign.Top;
DataGrid1.ItemStyle.HorizontalAlign=System.Web.UI.WebControls.HorizontalAlign.Left;
Table1 .Font.Size=9;
Table1.BorderWidth=0;
Table1.RenderControl(htmlWrite);
htmlWrite.WriteLine("
");
DataGrid1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
-------------
siply copy this code it will work fine