简体   繁体   English

如何从.net Windows桌面应用程序中的Datagrid打印数据

[英]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.

相关问题 如何从.NET调用Windows 7附带的“打印图片”应用程序 - How to invoke the “Print Pictures” application that comes with Windows 7 from .NET 如何从Windows应用程序中刮取数据网格 - How to scrape datagrid from a Windows Application 如何设置Windows 7的桌面应用程序外观(c#.net) - How to set windows 7 like look of desktop application (c#.net) Windows 桌面应用程序从浏览器读取 session 数据 - Windows desktop application read session data from browser .net 2.0 Datagrid视图组合框Windows应用程序 - .net 2.0 datagrid view combobox windows application 如何从 Windows 窗体应用程序的 DataGrid 中的选定行中获取值? - How to get values from selected row in DataGrid for Windows Form Application? 使用.NET平台的Windows桌面嵌入式应用程序? - An embedded application for windows desktop using .NET platform? 如何从Windows应用商店应用启动桌面应用? - How to launch a desktop application from windows store apps? 如何打开Windows资源管理器并从桌面应用程序搜索? - How to open Windows explorer and search from a desktop application? 如何从与桌面交互的应用程序与Windows服务进行通信? - How to communicate with a windows service from an application that interacts with the desktop?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM