I want to print reports based on GridView checkbox. If 3 rows have been chosen, there should be 3 reports. My code is like this...
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 != nu开发者_JAVA百科ll && 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);
}
...but currently this code can print report the last row only.
I tested this and it does open the three windows, you'll have to tweak it a bit by passing a list of selected IDs to Material, so that you call Material just once. Inside material in your string manipulation, after the following line,
Script += "<script language=JavaScript id='PopupWindow'>";
add a for loop that goes though the selected IDs and adds a window.open. So, the following lines should be in the for/foreach loop
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');";
and then the following lines follow and are outside the for loop.
Script += "confirmWin.Setfocus()</script>";
//ClientScript.RegisterStartupScript(typeof(string), "PopupScript", "PopupWindow");
if (!ClientScript.IsClientScriptBlockRegistered("PopupWindow"))
ClientScript.RegisterClientScriptBlock(typeof(string), "PopupWindow", Script);
This is my example and works. Also, would be better if you use StringBuilder instead of 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);
Hope this helps.
精彩评论