[英]How to print the data from Datagrid in .net Windows Desktop Application
I am displaying the data from the MS access database in the DataGrid of a .net windows desktop application. 我在.net Windows桌面应用程序的DataGrid中显示来自MS Access数据库的数据。 Now I want to print the data of the DataGrid or want to take the Printout of the data of DataGrid only not of whole page.
现在,我想打印DataGrid的数据,或者只想打印DataGrid的数据而不是整个页面。 Can anybody help me to sort out my problem?
有人可以帮我解决我的问题吗?
Please advice the answer in C# language. 请以C#语言建议答案。
EDIT 编辑
Since you're printing a WinForms DataGrid I suggest you take a look at: 由于您正在打印WinForms DataGrid,因此建议您看一下:
ORIGINAL 原版的
Kind of confused. 有点困惑。 I think you mean "Asp.net Web Applicaion" meaning this runs in a web-browser.
我认为您的意思是“ Asp.net Web应用程序”,它在Web浏览器中运行。
So I'll answer with that in mind (if I have it backwards let me know). 因此,我会记住这一点(如果我向后退让我知道)。
The easiest C# answer is to have a separate Print.aspx page. 最简单的C#答案是拥有一个单独的Print.aspx页面。 Just put a single GridView on the page and populate it with the same data from the previous page.
只需在页面上放置一个GridView,并使用上一页中的相同数据填充它即可。 That way when the user prints (File->Print) they'll only get the data and not the other stuff you're trying to avoid printing.
这样,当用户打印(文件->打印)时,他们只会获取数据,而不会获取您试图避免打印的其他内容。
Should also note that you can use JavaScript to invoke the print method of the browser as well, but this can't be done directly from C#. 还应注意,您也可以使用JavaScript调用浏览器的print方法,但这不能直接从C#中完成。
Why create 2 pages , just add a separate style sheet for print like : 为什么要创建2页,只需添加一个单独的样式表进行打印,例如:
<link href="/Styles/PrintStyle.css" rel=" stylesheet" type="text/css" media="print">
And in css 而在CSS
.NonPrintable
{
display: none;
}
.NonPrintable, #Menu, #Footer
{
display: none;
}
You can call the css class like : 您可以像这样调用css类:
<body>
<input type="YouCantPrintMe" value="I am hidden" class="NonPrintable">
</body>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.