0

私はここで ac# Web アプリを構築しており、Listview を持っています。クリックするとリストビューを簡単に印刷できるボタンをページに配置したいと思います。これがどのように行われるか誰にも分かりますか?

ありがとう ここに画像の説明を入力

4

2 に答える 2

0

There are 2 options that I can think of:

  1. Send this to a different page with an ID (perhaps the order number?) in the query string; read the order id from the query string, and output the details in the page. Then call window.print on window.load

Something like:

Order o = DAL.GetOrderByID(int.Parse(Request.QueryString["OrderID"]));
//output the order in this new page...

On this new page, have a line like this:

window.onload=function(){window.print();};
  1. Use this jquery plugin to do it. It creates a frame in the page and calls .print on the frame. Seems very simple to implement.
于 2012-08-30T15:38:51.237 に答える
0

ボタンクリックイベント内に次のコードを追加してみてください。それが役立つことを完全に願っています。

    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();
于 2012-08-30T15:59:32.447 に答える