我在这里构建 ac# web 应用程序,我有一个 Listview。我想在页面上有一个按钮,单击该按钮将轻松打印列表视图。任何人都知道如何做到这一点?
谢谢
我能想到2个选项:
window.print
然后打电话window.load
就像是:
Order o = DAL.GetOrderByID(int.Parse(Request.QueryString["OrderID"]));
//output the order in this new page...
在这个新页面上,有这样一行:
window.onload=function(){window.print();};
.print
该框架。实现起来似乎很简单。尝试在按钮单击事件中添加以下代码。完全希望它会有所帮助。
this.ListView1.DataBind();
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
ListView1.RenderControl(hw);
string ListViewHTML = sw.ToString().Replace("\"", "'").Replace(System.Environment.NewLine, "");
StringBuilder sb = new StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload = new function(){");
sb.Append("var printList = window.open('', '', 'left=0");
sb.Append(",top=0,width=800,height=700,status=0');");
sb.Append("printList.document.write(\"");
sb.Append(ListViewHTML);
sb.Append("\");");
sb.Append("printList.document.close();");
sb.Append("printList.focus();");
sb.Append("printList.print();");
sb.Append("printList.close();};");
sb.Append("</script>");
ClientScript.RegisterStartupScript(this.GetType(), "ListViewPrint", sb.ToString());
this.ListView1.DataBind();