如何使用ASP.NET GridView,RDLC打印多个报表?

时间:2011-01-20 05:34:40

标签: c# asp.net gridview reportviewer rdlc

我想打印基于GridView复选框的报告。如果选择了3行,则应该是3个报告。我的代码是这样的......

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);
    }

目前此代码只能打印报告最后一行...谁能帮助我?感谢

1 个答案:

答案 0 :(得分:2)

我对此进行了测试并确实打开了三个窗口,您必须通过将所选ID列表传递给Material来稍微调整一下,这样您只需调用一次Material。字符串操作中的内部材质,在以下行之后,

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

添加一个遍历所选ID的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 + =

,会更好
        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);

希望这有帮助。