我正在asp.net上做一个项目
我使用Devexpress gridview 9.1。
我想在按钮点击时打印 gridview only 。 基本上页面中没有其他控件。
我发现,这可以通过将网格传递到下一页并在那里打印来实现。 但我的要求不允许这样做。
所以可以通过任何方式在同一页上单独打印 gridview吗?
答案 0 :(得分:0)
为此目的使用stanalone ASPxGridViewExporter组件:
http://demos.devexpress.com/ASPxGridViewDemos/Exporting/Exporting.aspx
答案 1 :(得分:0)
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)
{
}
}