Click here to Skip to main content
15,892,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I printed a table my page in C# using following code
C#
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);


I simply printed a table using above code

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

Please Help me.
Posted

1 solution

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[^]
 
Share this answer
 
Comments
RaviRanjanKr 4-Aug-11 9:06am    
Nice Links, My 5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900