Why not gridview header printed in color on print
I am trying Gridview print in the javascript. But when i see preview a page.Gridview is not showing header color in.
asp:Content ID="Content1" ContentPlaceHolderID="cHead" runat="Server">
<script type="text/javascript">
function CallPrint(strid) {
var prtContent = document.getElementById(strid);
var WinPrint = window.open('', '', 'letf=0,top=0,width=400,height=400,toolbar=0,scrollbars=0,status=0');
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
}
</script>
<style type="text/css">
.head
{
background-color: #293339 !important;
-webkit-print-color-adjust: exact;
color: White !important;
-webkit-print-color-adjust: exact;
}
</style>
<style type="text/css">
@media print
{
th
{
background-color: black;
color: white;
}
tHead
{
display: table-header-group;
}
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="mBody" runat="Server">
<div id="divPrint">
<asp:GridView ID="GridView1" runat="server">
<HeaderStyle CssClass="head" />
</asp:GridView>
</div>
<input type="button" value="print " id="btnPrint" runat="Server" onclick="javascript:CallPrint('divPrint')" />
</asp:Content>
code:
====
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridView1.DataSource = GetDataTable();
GridView1.DataBind();
}
}
private DataTable GetDataTable()
{
//create table
DataTable dt = new DataTable("Product");
dt.Columns.Add("ProductID", Type.GetType("System.Int32"));
dt.Columns.Add("ProductName", Type.GetType("System.String"));
//create fields
DataColumn[] pk = new DataColumn[1];
pk[0] = dt.Columns["ProductID"];
dt.PrimaryKey = pk;
dt.Columns["ProductID"].AutoIncrement = true;
dt.Columns["ProductID"].AutoIncrementSeed = 1;
dt.Columns["ProductID"].ReadOnly = true;
//fill rows
DataRow dr;
for (int x = 1; x <= 10; x++)
{
//make every other one different
if (Math.IEEERemainder(x, 2) == 0)
{
dr = dt.NewRow();
dr["ProductName"] = "Riss";
dt.Rows.Add(dr);
}
else
{
dr = dt.NewRow();
dr["ProductName"] = "Product";
dt.Rows.Add(dr);
}
}
return dt;
}