Reputation: 2131
I'm trying to allow a user to print multiple tables depending on what they select in the GridView. It will then select more data (from a hidden GridView) and print all the tables accordingly. What I am doing right now is taking the table at the bottom of my page, giving it a div id, and then using jJavascript to open that div in a new window. However, I'd like to be able to print multiple tables at a time, and possibly even print them on individual pages. Is there a special way to go about doing this? Some sort of special function?
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>
How I fill my table
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();
The table itself
<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>
Upvotes: 1
Views: 3194
Reputation: 14906
You can use CSS's page-break-before
to print content on separate pages:
<table style="page-break-before: always;">
...
</table>
This would insert a page break before all tables. You'll probably want to apply this to all tables after the first.
Upvotes: 1
Reputation: 19772
To make sure there's a page break, use the page-break-before: always
CSS styling on each element you want to make a page break.
Upvotes: 1