<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script type = "text/javascript">
function Print(a) {
a.style.display = "none";
var row = a.parentNode.parentNode;
var printWin = window.open('', '', 'left=0", ",top=0,width=1000,height=600,status=0');
printWin.document.write(row.innerHTML);
printWin.document.close();
printWin.focus();
printWin.print();
printWin.close();
a.style.display = "block";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns = "false" GridLines = "Both">
<Columns>
<asp:BoundField DataField = "Item" ItemStyle-Width = "100"/>
<asp:BoundField DataField = "Price" ItemStyle-Width = "100" />
<asp:TemplateField>
<ItemTemplate>
<a href = "javascript:;" onclick = "Print(this)">Print</a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[2] { new DataColumn("Item"), new DataColumn("Price") });
dt.Rows.Add("Shirt", 199);
dt.Rows.Add("Football", 20);
dt.Rows.Add("Shirt", 22.5);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
Demo