2011-01-20 66 views
1

我想打印基於GridView的報表複選框。如果選擇了3行,應該是3個報告。我的代碼是這樣的...如何使用ASP.NET GridView,RDLC打印多個報表?

protected void btn_Print_Click(object sender, EventArgs e) 
    { 
     if (IsPostBack) 
     { 
      try 
      { 
       foreach (GridViewRow gvr in grdRV.Rows) 
       { 
        RadioButton rbID = (RadioButton)gvr.FindControl("rbID") as RadioButton; 

        if (rbID != null && rbID.Checked) 
        { 
         string sID = grdRV.DataKeys[gvr.RowIndex].Value.ToString().Trim(); 

         if (rbl_Print.SelectedValue == "0") 
         { 
          SMTP(sID); 
         } 
         else if (rbl_Print.SelectedValue == "1") 
         { 
          Material(sID); 
         } 
        } 
       } 
      } 
      catch (Exception ex) 
      { 
       Session["error"] = ex.Message; 
       Response.Redirect("MessageBoard.aspx"); 
      } 
     } 
    } 

private void Material(string sID) 
    {    

     string querystring = "../pmis/Reports/RptRFQMatV.aspx?RFQNo=" + lblRFQNo.Text.ToString() + "&ID=" + sID; 

     Random r = new Random();    
     string Script = ""; 
     Script += "<script language=JavaScript id='PopupWindow'>"; 
     Script += "confirmWin = window.open(' " + querystring + "','" + r.Next() + "','scrollbars=yes,resizable=1, width=960,height=500,left=50,top=130,status');"; 
     Script += "confirmWin.Setfocus()</script>"; 

     //ClientScript.RegisterStartupScript(typeof(string), "PopupScript", "PopupWindow"); 
     if (!ClientScript.IsClientScriptBlockRegistered("PopupWindow")) 
      ClientScript.RegisterClientScriptBlock(typeof(string), "PopupWindow", Script); 
    } 

當前這段代碼可以打印報告最後一行......誰能幫我?謝謝

+0

當您在此代碼中設置斷點時會發生什麼?爲什麼它沒有抓住你期望的3? – 2011-01-20 05:43:21

+0

@ p.campbell:讓我說我檢查了3行,我會有3個ID。例如:A0031,A0027,A0051。所以首先A0031進入材料塊,完成A0027後,然後A0051。所以報告只適用於A0051。其他兩個ID不出來。可能會被覆蓋或其他東西... – CMMaung 2011-01-20 06:01:16

回答

2

我測試了這個,它確實打開了三個窗口,您必須將所選ID的列表傳遞給材質,以便您只調用一次材質。在裏面你的字符串操作材料,經過以下行,

Script += "<script language=JavaScript id='PopupWindow'>"; 

添加一個for循環,去雖然選擇的標識,並增加了window.open。因此,以下行應在for/foreach循環中:

string querystring = "../pmis/Reports/RptRFQMatV.aspx?RFQNo=" + lblRFQNo.Text.ToString() + "&ID=" + sID; 


Script += "confirmWin = window.open(' " + querystring + "','" + r.Next() + "','scrollbars=yes,resizable=1, width=960,height=500,left=50,top=130,status');"; 

然後接下來的行跟在for循環之外。

Script += "confirmWin.Setfocus()</script>"; 

     //ClientScript.RegisterStartupScript(typeof(string), "PopupScript", "PopupWindow"); 
     if (!ClientScript.IsClientScriptBlockRegistered("PopupWindow")) 
      ClientScript.RegisterClientScriptBlock(typeof(string), "PopupWindow", Script); 

這是我的榜樣和作品。此外,如果您使用StringBuilder而不是字符串會更好 - +

 string Script = ""; 
     Script += "<script language=JavaScript id='PopupWindow'>"; 
     Script += "window.open('www.google.com.au', '1','scrollbars=yes,resizable=1, width=960,height=500,left=50,top=130,status');"; 
     Script += "window.open('www.yahoo.com','2','scrollbars=yes,resizable=1, width=960,height=500,left=50,top=130,status');"; 
     Script += "window.open('www.stackoverflow.com','3', 'scrollbars=yes,resizable=1, width=960,height=500,left=50,top=130,status');"; 
     Script += "</script>"; 

     if (!ClientScript.IsClientScriptBlockRegistered("PopupWindow")) 
      ClientScript.RegisterClientScriptBlock(typeof(string), "PopupWindow", Script); 

希望這會有所幫助。