如何打印在c#中动态创建的html表 [英] How do I print an html table that is dynamically created in c#

查看:85
本文介绍了如何打印在c#中动态创建的html表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我使用的javascript代码



This is the javascript code that I use

function Print() {
    var prntData = document.getElementById('Table1');
    var mywindow = window.open('', 'printer', 'height=400,width=600');
    mywindow.document.write('<html><head><title></title>');
    mywindow.document.write('</head><body style="direction:rtl;"><pre>');
    mywindow.document.write(prntData.innerHTML);
    mywindow.document.write('</body></html>');
    mywindow.document.close();
    mywindow.print();
}





这是我的html表



This is my html table

<table style="width: 100%;" class="MemberTbl"  runat="server" id="Table1">





我注意到当我自己创建表并打印它时,代码可以工作但是当我创建时它dy使用runat = server,在打印按钮上单击它只会打开一个空白框。



如何实现这个



欢迎任何帮助



I noticed that when I created the table myself and print it the code works but when I create it dynamically with a runat=server, on print button click it only brings up an empty white box.

How can a achieve this

Any help is welcome

推荐答案

您好,

当您使用runat = server动态创建它时,元素的id将改变。

它将是这样的:containerId_containerId_Table1。

因此,在你的打印函数中,你的第一行代码将不会返回任何内容。

我希望它很清楚。



您可以使用像jQuery这样的库来使用这种方法获取HTML元素:

带选择器的属性结尾[name
Hello,
When you create it dynamically with a runat=server, the id of the element will change.
It will be something like this : "containerId_containerId_Table1".
So, in your print function, your first line of code will return nothing.
I hope it's clear.

You can use a library like jQuery to get your HTML element with this method :
Attribute Ends With Selector [name


=value]
="value"]


您好,您可以添加[ClientIDMode =Static]属性。



参见 http://msdn.microsoft.com/en-us/library/vstudio/system.web.ui.control.clientidmode(v = vs.100).aspx [更多关于ClientIDMode属性的信息]



最好的问候。
Hello, you could add the [ClientIDMode="Static"] attribute.

See http://msdn.microsoft.com/en-us/library/vstudio/system.web.ui.control.clientidmode(v=vs.100).aspx[more info about the ClientIDMode attribute]

Best Regards.


这篇关于如何打印在c#中动态创建的html表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆