开发者

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. 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. Can anybody help me to sort out my problem?

Please advice the answer in C# languag开发者_StackOverflow社区e.


Why create 2 pages , just add a separate style sheet for print like :

<link href="/Styles/PrintStyle.css" rel=" stylesheet" type="text/css" media="print">

And in css

.NonPrintable
{
 display: none;
 }
 .NonPrintable, #Menu, #Footer 
 {
  display: none;
 }

You can call the css class like :

<body>
<input type="YouCantPrintMe" value="I am hidden" class="NonPrintable">
</body>


EDIT

Since you're printing a WinForms DataGrid I suggest you take a look at:

  • Code: Printing a DataGrid (Visual C#)
  • Printing a DataGridView on DotNet Framework
  • Printing Selected Columns and Rows in a DataGrid

ORIGINAL

Kind of confused. I think you mean "Asp.net Web Applicaion" meaning this runs in a web-browser.

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. Just put a single GridView on the page and populate it with the same data from the previous page. 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#.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜