Saturday, 3 August 2013

Print Selected section using Window.Print

<%@ Page Language="C#" >
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Print</title>
   
    <style>
         @media print
          {
            #Panel2
            {
                display:none;
            }
          }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Panel ID="Panel1" runat="server" style="width: 100%">
                <table style="width: 100%" border="0" align="center" cellspacing="1" cellpadding="5"       >                                 
                    <tr>
                        <td style="border: solid 1px #AEAEBB;" >
                            <b>Name</b>
                        </td>
                        <td style="width: 50%; border: solid 1px #AEAEBB;">
                           Sujoy Santra
                        </td>
                    </tr>
                    <tr>
                        <td style="border: solid 1px #AEAEBB;" >
                            <b>Address</b>
                        </td>
                        <td style="width: 50%; border: solid 1px #AEAEBB;">
                           Kolkata                     
             </td>
                    </tr>
                   </table>
        </asp:Panel>
        <asp:Panel ID="Panel2" runat="server" style="width: 100%">      
        <table style="width:100%" border="0" align="center" cellspacing="1"
            cellpadding="8" >          
            <tr>
                 <td style="width: 50%; border: solid 1px #AEAEBB;" align="right">
                    <a href="#" onclick="javascript:window.close();"><b>Close</b></a>                   
                </td>             
                <td style="width: 50%; border: solid 1px #AEAEBB;" align="left">
                    <a href="#" onclick="javascript:window.print();"><b>Print</b></a>
                </td>
            </tr>
        </table>
         </asp:Panel>
    </div>
    </form>
</body>
</html>