Click Here for 3 Month Free of ASP.NET Hosting!
Home | Submit an interview question | Filter by category | Filter by job function | Filter by company
 
Member Information
User Id
Password
 
Forgot Password
Technology Category
.NET (1202)
Languages (103)
Database (146)
Operating System (48)
Reporting (5)
Third-Party Tools (2)
Testing (91)
OOP (75)
Web Development (40)
Design Patterns (89)
General (9)
Networking (88)
Hardware (63)
Brain Exercise (2)
Others (37)
 Our Network
.NET Heaven
C# Corner
Interview Corner
Longhorn Corner
Mindcracker
VB.NET Heaven
Home » .NET » .NET
How to export datagrid to excel,note pad,PDF using Asp.Net?
Posted by Oct 30, 2006
Viewed : 5303 times
Major Category : .NET
Minor Category : ASP.NET
Total Replies : 2
Become a Sponsor
 EDITORIAL ANSWER  
No Reply Yet
 ANSWERS BY USERS  
sumanth praveen
Nov 03, 2006

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 = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

DataGrid1.ForeColor=Color.Black;

DataGrid1.HeaderStyle.BackColor=Color.White;

DataGrid1.HeaderStyle.Font.Bold=true;

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

htmlWrite.WriteLine("

");

Response.Write(stringWrite.ToString());

Response.End();

-------------

siply copy this code it will work fine

 

 

 


Oct 30, 2006
How to export datagrid to excel,note pad,PDF using Asp.Net?
  
1

 

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Advertise with us
Current Version: 2.2009.3.2
 © 1999 - 2009  Mindcracker LLC. All Rights Reserved