在父页面弹出子页面出错 求大神
我在父页面里弄了个gridview 想点击gridview 获取其中的三个值(已实现)并在该页面上弹出新的子页面且传过去一局sql语句 却出现错误 求指点 下面上代码
protected void GrvGMMailbox_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)这是父页面的代码 重点在response.write上 运行后报错说sql未定义 (gridview的datakeyname 写的是id 不知与这有没有关系 反正我改成sql也不行) 求指点
{
name = GrvGMMailbox.Rows[e.NewSelectedIndex].Cells[1].Text;
reportID= GrvGMMailbox.Rows[e.NewSelectedIndex].Cells[3].Text;
type= GrvGMMailbox.Rows[e.NewSelectedIndex].Cells[4].Text;
//Label1.Text = department;
//Label2.Text = reportID;
//Label3.Text = type;
ReportInfo();
}
protected void ReportInfo()
{
//判断报告类型来决定需要进行查询的表
if (type == "维修完成报告")
{
string sql = "select * from EP_TblMalfunctionRepairResults where ID='" + reportID + "' and RepairName='" + name + "'";
}
if (type == "复查报告")
{
string sql = "select * from EP_TblMalfunctionCheckResult whereID='" + reportID + "' and InspectorName='" + name + "'";
}
if (type=="故障报告")
{
string sql = "select * from EP_TblMalfunctionReport whereID='" + reportID + "' and ReportName='" + name + "'";
}
Response.Write("<script>window.showModalDialog('ShowReportInfo.aspx?sql=' + sql,'', 'width=481;sheight=300;status=no;resizable=no;screenX=300;screenY=350;top=200;left=300');</script>");
}
这是ShowReportInfo的代码
protected void Page_Load(object sender, EventArgs e)
{
a = Request.QueryString["sql"].ToString();
//b = Request.QueryString["ReportID"].ToString();
Label1.Text = a;
//Label2.Text = b;
}
[解决办法]
他们俩只不过字符串没分割好,主要意思是你原来把sql放在字符串里面当然不行,这点错误自己修改下还不行?
Response.Write("<script>window.showModalDialog('ShowReportInfo.aspx?sql=" + sql + "';width=481;sheight=300;status=no;resizable=no;screenX=300;screenY=350;top=200;left=300');</script>");
建议用2楼的方法