VC# ASP.NET 简单区域打印
2011-08-26 09:28
309 查看
全为前台js控制:
js涵数:
NEW一个html的Button,做上onclick事件如下
<input id="Button1" type="button" value="打印" onclick="printView('user_print')"/>
//JS涵数据
<script type="text/javascript">
function printView(id_print)
{ var aa=document.getElementById(id_print).outerHTML;
var bb=window.document.body.innerHTML
window.document.body.innerHTML=aa;
window.print();
window.document.body.innerHTML=bb;
}
</script>
//要打印的区域DIV id=user_print
<div id="user_print">
<input id="Button1" type="button" value="打印" onclick="printView('user_print')"> />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button2" runat="server" Text="查询" onclick="Button2_Click" />
<asp:Button ID="Button3" runat="server" Text="导出" onclick="Button3_Click" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px"
CellPadding="4"
onselectedindexchanged="GridView1_SelectedIndexChanged" Width="1012px"
AllowPaging="True" oninit="GridView1_Init" PageSize="2"
style="text-align: center"
onpageindexchanging="GridView1_PageIndexChanging"
onrowcommand="GridView1_RowCommand">
<RowStyle BackColor="White" ForeColor="#330099" />
<Columns>
<asp:BoundField DataField="User_id" HeaderText="账号" />
<asp:BoundField DataField="Password" HeaderText="密码" />
<asp:BoundField DataField="Chi_Name" HeaderText="中文姓名" />
<asp:BoundField DataField="Company_code" HeaderText="公司名称" />
<asp:BoundField DataField="Dept_ID" HeaderText="部门/单位" />
<asp:BoundField DataField="Role_id" HeaderText="角色" />
<asp:BoundField DataField="Eng_Name" HeaderText="英文名" />
<asp:BoundField DataField="E-Mail" HeaderText="联系邮箱" />
<asp:BoundField DataField="Phone" HeaderText="联系电话" />
</Columns>
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
<PagerTemplate>
<asp:Label ID="lbl_page_size1" runat="server" Text='<%# "每页"+GridView1.PageSize+"条" %>'></asp:Label>
<asp:Label ID="lblPage" runat="server" Text='<%# "第" + (((GridView)Container.NamingContainer).PageIndex + 1) + "页/共" + (((GridView)Container.NamingContainer).PageCount) + "页" %> '></asp:Label>
<asp:LinkButton ID="lbnFirst" runat="Server" Text="首页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>' CommandName="Page" CommandArgument="First" ></asp:LinkButton>
<asp:LinkButton ID="lbnPrev" runat="server" Text="上一页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>' CommandName="Page" CommandArgument="Prev" ></asp:LinkButton>
<asp:LinkButton ID="lbnNext" runat="Server" Text="下一页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>' CommandName="Page" CommandArgument="Next" ></asp:LinkButton>
<asp:LinkButton ID="lbnLast" runat="Server" Text="尾页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>' CommandName="Page" CommandArgument="Last" ></asp:LinkButton>
到第
<asp:TextBox runat="server" ID="inPageNum"></asp:TextBox>页<asp:Button ID="Button1" CommandName="go" runat="server" Text="GO" />
</PagerTemplate>
</asp:GridView>
</div>
要打印那个区域,把DIV换一下就行了,按下打印按钮时会出现打印浏览的
相关文章推荐
- asp.net导出excel和打印指定内容的简单代码
- asp.net页面打印的简单控制
- asp.net(c#)打印excel大数据量,最简单,最快的办法,个人认为,哈哈,有人会说,用gridview打印excel不是很方便吗?但是我发现数据量一大gridview就不行,速度慢不说,还会出错
- asp.net 简单分页打印
- asp.net控制打印区域
- 在Asp.Net Core中添加区域的简单实现
- ASP.NET区域打印功能
- ASP.NET区域打印功能
- Asp.Net MVC3 简单入门第一季(五) 通过Asp.Net MVC的区域功能实现将多个MVC项目部署到一个站点
- ASP.NET里实现水晶报表的打印
- Asp.net如何使用access数据库做profile实现按照区域显示相应语言功能
- Asp.net 网络打印 – WebBrowser 控件技术打印
- asp.net打印代碼
- ASP.NET网络编程学习第二步:简单理解ASP.NET
- asp.net简单生成验证码的方法
- ASP.NET Atlas简单控件介绍——Sys.Component基类与Sys.UI.Control基类
- 关于ASP.NET页面打印技术的总结
- ASP.NET网页打印(只打印相关内容/自写功能)
- asp.net 打印功能 Demo
- 使用ASP.NET实现Friendly URL的最简单方法