Reputation: 327
I am doing a project on asp.net
I use Devexpress gridview 9.1 .
I would like to print the gridview only on a button click. Basically no other controls in the page should be printed.
I found that, this is possible by passing the grid to next page and printing it there. But my requirement doesn't allow that.
so is it possible to print the gridview alone on the same page by any means??
Upvotes: 0
Views: 1562
Reputation: 905
protected void ASPxButton1_Click(object sender, EventArgs e)
{
using(MemoryStream ms = new MemoryStream()){
PrintableComponentLink pcl = new PrintableComponentLink(new PrintingSystem());
pcl.Component = ASPxGridViewExporter1;
pcl.Margins.Left = pcl.Margins.Right = 50;
pcl.Landscape = true;
pcl.CreateDocument(false);
pcl.PrintingSystem.Document.AutoFitToPagesWidth = 1;
pcl.ExportToPdf(ms);
WriteResponse(this.Response, ms.ToArray(), System.Net.Mime.DispositionTypeNames.Inline.ToString());
}
}
public static void WriteResponse(HttpResponse response, byte[] filearray, string type)
{
response.ClearContent();
response.Buffer = true;
response.Cache.SetCacheability(HttpCacheability.Private);
response.ContentType = "application/pdf";
ContentDisposition contentDisposition = new ContentDisposition();
contentDisposition.FileName = "test.pdf";
contentDisposition.DispositionType = type;
response.AddHeader("Content-Disposition", contentDisposition.ToString());
response.BinaryWrite(filearray);
HttpContext.Current.ApplicationInstance.CompleteRequest();
try
{
response.End();
}
catch (System.Threading.ThreadAbortException)
{
}
}
Upvotes: 0
Reputation: 9285
Use the stanalone ASPxGridViewExporter component for this purpose:
http://demos.devexpress.com/ASPxGridViewDemos/Exporting/Exporting.aspx
Upvotes: 0