1

我有使用面板来保存数据列表。

用于在数据列表中显示 img 的 aspx 代码

<asp:Image ID="Image2" ImageUrl='<%# Eval("FilePath") %>' Width="120px" Height="180px"     runat="server" /> 

后面的代码:

    StringWriter sw = new System.IO.StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    panel.RenderControl(hw);
    string html = 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 printWin = window.open('', '', 'left=0");
    sb.Append(",top=0,width=1000,height=600,status=0');");
    sb.Append("printWin.document.write(\"");

    sb.Append(html);
    sb.Append("\");");
    sb.Append("printWin.document.close();");
    sb.Append("printWin.focus();");
    sb.Append("printWin.print();printWin.opener.location.href=printWin.opener.location.href;");
    sb.Append("printWin.close();};");
    sb.Append("</script>");

ClientScript.RegisterStartupScript(this.GetType(), "打印", sb.ToString());

4

0 回答 0