Refer the below code.
HTML
<asp:Panel ID="pnlContents" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" Font-Names="Arial"
Font-Size="11pt" AlternatingRowStyle-BackColor="#C2D69B" HeaderStyle-BackColor="green"
AllowPaging="false">
<Columns>
<asp:BoundField ItemStyle-Width="150px" DataField="ENO" HeaderText="ENO" />
<asp:BoundField ItemStyle-Width="150px" DataField="ENAME" HeaderText="ENAME" />
<asp:BoundField ItemStyle-Width="150px" DataField="JOB" HeaderText="JOB" />
<asp:BoundField ItemStyle-Width="150px" DataField="MGR" HeaderText="MGR" />
<asp:BoundField ItemStyle-Width="150px" DataField="HIRDATE" HeaderText="HIRDATE" />
<asp:BoundField ItemStyle-Width="150px" DataField="SAL" HeaderText="SAL" />
<asp:BoundField ItemStyle-Width="150px" DataField="COMM" HeaderText="COMM" />
<asp:BoundField ItemStyle-Width="150px" DataField="DEPTNO" HeaderText="DEPTNO" />
</Columns>
</asp:GridView>
</asp:Panel>
<br />
<asp:Button ID="btnPrint" runat="server" Text="Print" OnClientClick="return PrintPanel();" />
<script type="text/javascript">
function PrintPanel() {
var panel = document.getElementById("<%=pnlContents.ClientID %>");
var printWindow = window.open('', '', 'height=400,width=800');
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>
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[]
{
new DataColumn("ENO"),new DataColumn("ENAME"),new DataColumn("JOB"),new DataColumn("MGR"),
new DataColumn("HIRDATE"),new DataColumn("SAL"),new DataColumn("COMM"),new DataColumn("DEPTNO")
});
dt.Rows.Add(1, "John Hammond", "Testing", "Mudassar Khan", "2016/05/08", "1000", "100", "1");
dt.Rows.Add(2, "Mudassar Khan", "Director", "Mudassar Khan", "2016/05/08", "1500", "150", "2");
dt.Rows.Add(3, "Suzanne Mathews", "Developer", "Mudassar Khan", "2016/05/08", "500", "50", "2");
dt.Rows.Add(4, "Robert Schidner", "Admin", "Mudassar Khan", "2016/05/08", "500", "50", "1");
GridView1.DataSource = dt;
GridView1.DataBind();
}
}