我正在尝试允许用户根据他们在GridView中选择的内容来打印多个表。然后它将选择更多数据(来自隐藏的GridView)并相应地打印所有表。我现在正在做的是把我的页面底部的表格给它一个div id,然后使用jJavascript在新窗口中打开该div。但是,我希望能够一次打印多个表格,甚至可以在各个页面上打印。这有什么特别的方法吗?某种特殊功能?
的Javascript
<script type='text/javascript'>
//<![CDATA[
function printContent() {
str = document.getElementById('main-content').innerHTML
newwin = window.open('', 'printwin', 'left=20,top=30,width=600,height=400')
newwin.document.write('<HTML>\n<HEAD>\n')
newwin.document.write('<TITLE>Print Page</TITLE>\n')
newwin.document.write('<script>\n')
newwin.document.write('function chkstate(){\n')
newwin.document.write('if(document.readyState=="complete"){\n')
newwin.document.write('window.close()\n')
newwin.document.write('}\n')
newwin.document.write('else{\n')
newwin.document.write('setTimeout("chkstate()",2000)\n')
newwin.document.write('}\n')
newwin.document.write('}\n')
newwin.document.write('function print_win(){\n')
newwin.document.write('window.print();\n')
newwin.document.write('chkstate();\n')
newwin.document.write('}\n')
newwin.document.write('<\/script>\n')
newwin.document.write('</HEAD>\n')
newwin.document.write('<BODY onload="print_win()">\n')
newwin.document.write(str)
newwin.document.write('</BODY>\n')
newwin.document.write('</HTML>\n')
newwin.document.close()
} //]]>
</script>
我如何填写表格
GridViewRow row = DefaultGrid.SelectedRow;
int rowIndex = DefaultGrid.SelectedIndex;
HiddenGrid.SelectedIndex = rowIndex;
GridViewRow row2 = HiddenGrid.SelectedRow;
//int id = Convert.ToInt32(row.Cells[25].Text);
fName = row2.Cells[0].Text;
lName = row2.Cells[1].Text;
addr = row2.Cells[2].Text;
addr2 = row2.Cells[3].Text;
city = row2.Cells[4].Text;
state = row2.Cells[5].Text;
zip = row2.Cells[6].Text;
country = row2.Cells[7].Text;
email = row2.Cells[8].Text;
phone = row2.Cells[9].Text;
ccType = row2.Cells[10].Text;
ccNum = row2.Cells[11].Text;
ccExp = row2.Cells[12].Text;
length = row2.Cells[13].Text;
delivery = row2.Cells[14].Text;
price = row2.Cells[15].Text;
source = row2.Cells[16].Text;
joined = row2.Cells[17].Text;
url = row2.Cells[18].Text;
orderResults = row2.Cells[19].Text;
pubName = row2.Cells[20].Text;
sourceCode = row2.Cells[21].Text;
dt = row.Cells[1].Text.ToString();
表格本身
<div id = 'main-content' style = "overflow: auto; height:50%; width:100%" />
<table id="details">
<tr>
<td style="width: 100px;">Name: </td>
<td><%=fName %> <%=lName %></td>
</tr>
<tr>
<td>Address: </td>
<td><%=addr %></td>
</tr>
<tr>
<td>Address 2: </td>
<td><%=addr2 %></td>
</tr>
<tr>
<td>City: </td>
<td><%=city %></td>
</tr>
<tr>
<td>State: </td>
<td><%=state %></td>
</tr>
<tr>
<td>Zip: </td>
<td><%=zip %></td>
</tr>
<tr>
<td>Country: </td>
<td><%=country %></td>
</tr>
<tr>
<td>Email: </td>
<td><a href="mailto:<%=email %>"><%=email %></a></td>
</tr>
<tr>
<td>Phone: </td>
<td><%=phone %></td>
</tr>
<tr>
<td>CCType: </td>
<td><%=ccType %></td>
</tr>
<tr>
<td>CCNum: </td>
<td><%=ccNum %></td>
</tr>
<tr>
<td>CCExp: </td>
<td><%=ccExp %></td>
</tr>
<tr>
<td>Length: </td>
<td><%=length %></td>
</tr>
<tr>
<td>Delivery: </td>
<td><%=delivery %></td>
</tr>
<tr>
<td>Price: </td>
<td><%=price %></td>
</tr>
<tr>
<td>Source: </td>
<td><%=source %></td>
</tr>
<tr>
<td>Joined: </td>
<td><%=joined %></td>
</tr>
<tr>
<td>URL: </td>
<td><%=url %></td>
</tr>
<tr>
<td>orderResults</td>
<td><%=orderResults %></td>
</tr>
<tr>
<td>PubName: </td>
<td><%=pubName %></td>
</tr>
<tr>
<td>Source Code: </td>
<td><%=sourceCode %></td>
</tr>
<tr>
<td>Date/Time: </td>
<td><%=dt %></td>
</tr>
</table>
</div>
答案 0 :(得分:1)
要确保有分页符,请在要分页的每个元素上使用page-break-before: always
CSS样式。
答案 1 :(得分:1)
您可以使用CSS的page-break-before
在不同的网页上打印内容:
<table style="page-break-before: always;">
...
</table>
这将在所有表之前插入分页符。您可能希望在第一个表之后将其应用于所有表。