VC# ASP.NET 简单区域打印

来源:互联网 发布:淘宝会员冻结怎么解冻 编辑:程序博客网 时间:2024/06/03 20:35

 

全为前台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" />
        &nbsp;
        <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换一下就行了,按下打印按钮时会出现打印浏览的

原创粉丝点击