将CSS应用于要打印的页面 [英] Apply CSS to the page to be printed

查看:80
本文介绍了将CSS应用于要打印的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码在C#中打印了一张表格我的页面

I printed a table my page in C# using following code

System.Web.UI.WebControls.DataGrid dg = new System.Web.UI.WebControls.DataGrid();   DataTable tempTbl = new DataTable();
//get my table columns here
        dg.DataSource = tempTbl;
        dg.AllowPaging = false;
        dg.AutoGenerateColumns = true;
        dg.DataBind();
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        dg.RenderControl(hw);
        string gridHTML = sw.ToString().Replace("\"", "'")
            .Replace(System.Environment.NewLine, "");
        StringBuilder sb = new StringBuilder();
        sb.Append("<script language='javascript' type='text/javascript'>");
        sb.Append("window.onload = new function(){");
        sb.Append("var printWin = window.open ('','','left =' + screen.width + ',top=' + screen.height + ',width=0,height=0,toolbar=0,scrollbars=0,status=0');");
        sb.Append("printWin.document.write(\"");
       sb.Append(gridHTML);          
        sb.Append("\");");
        sb.Append("printWin.document.close();");
        sb.Append("printWin.focus();");
        sb.Append("printWin.print();");
        sb.Append("printWin.close();};");
        sb.Append("</script>");           System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), "JSCR", sb.ToString(), false);



我只是使用上面的代码打印了一张桌子

如何将CSS应用于要打印的表

请帮助我.



I simply printed a table using above code

how to apply CSS to the table that is to be printed

Please Help me.

推荐答案

在Codeproject中有一些用于此目的的文章
查看这些链接
为您的数据网格添加一些样式 [ http://devpinoy.org/blogs/joeycalisay/archive/2006/06/21/css-with-datagrid.aspx [ ^ ]
There some artical for this purpose in Codeproject
look into these links
Add some Style to your DataGrids[^]
and this
http://devpinoy.org/blogs/joeycalisay/archive/2006/06/21/css-with-datagrid.aspx[^]


这篇关于将CSS应用于要打印的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆