Print panel Area in Asp.net
Print panel Area in Asp.net
In this article I am using print function for print a
particular area .
Step 1:- Design web Page .aspx
<head>
<title></title>
<script type = "text/javascript">
function Print() {
var panel = document.getElementById("<%=pnlContents.ClientID %>");
var printWindow = window.open('', '', 'height=500,width=500');
printWindow.document.write('<html><head><title>DIV
Contents</title>');
printWindow.document.write('</head><body >');
printWindow.document.write(panel.innerHTML);
printWindow.document.write('</body></html>');
printWindow.document.close();
setTimeout(function () {
printWindow.print();
}, 500);
return false;
}
</script>
</head>
<body>
<form id="form1" runat = "server">
<asp:Panel id="pnlContents" runat = "server">
CliCk Button fro Print This Area.
<asp:GridView ID="gr" runat="server" HeaderStyle-BackColor="#3366ff" HeaderStyle-ForeColor="White" AlternatingRowStyle-BackColor="WhiteSmoke" Width="40%"></asp:GridView>
</asp:Panel>
<br />
<asp:Button ID="btnPrint" runat="server" Text="Print Area" OnClientClick = "return Print();" BackColor="YellowGreen" />
</form>
</body>
Step 2:- Logic on .cs
protected void Page_Load(object sender, EventArgs e)
{
//Create
DataTable for populating Test Data for
Gridview.
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Columns.Add("City");
dt.Rows.Add("kandy", "Delhi");
dt.Rows.Add("sam", "delhi");
dt.Rows.Add("Sahil", "Hr");
dt.Rows.Add("jonny", "delhi");
//Bind
Gridview Using DataTable
gr.DataSource = dt;
gr.DataBind();
}
Comments
Post a Comment