GridView子窗口向父窗口传值问题?

来源:互联网 发布:泉州网络电视台 编辑:程序博客网 时间:2024/05/16 05:56

一.子窗体向父窗体传值

1、父窗体:
<script type="text/javascript">
        function XuanZeContract()
        {
            window.showModalDialog('子窗体.aspx','newwindow','height=300,width=500,top='+(screen.AvailHeight-300)/2+',left='+(screen.AvailWidth-300)/2+',toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');
        }

父窗体后台取值:

TextBox1.Text = Request.QueryString["id"];


HTML code:


 <input id="Button3" type="button" value="选择" onclick="XuanZeContract()" />


2、子窗体后台双击选择:


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //鼠标双击事件
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onDblClick", "javascript:opener.location.href='父窗体.aspx?id=" + e.Row.Cells[1].Text.ToString() + "';window.close();");
        }
    }


二、现在又是父窗体向子窗体传值


 1、父窗体:

 <ItemTemplate>
                        <asp:LinkButton ID="LinkButton5" runat="server" ForeColor="#000066">查看</asp:LinkButton>
                        <asp:Label ID="Label2" runat="server"
                            Text='<%#DataBinder.Eval(Container.DataItem, "F_name")%>' Visible="False" Width="0px"></asp:Label>
                    </ItemTemplate>

C# code

if (e.Row.RowType == DataControlRowType.DataRow)
  {
  LinkButton l = (LinkButton)e.Row.FindControl("LinkButton5");
  Label b = (Label)e.Row.FindControl("Label2");
  string Temp = b.Text.ToString();
  l.Attributes.Add("onclick", "window.showModalDialog('ContractParticularData.aspx?id="+Server.UrlEncode(Temp)+"','window','dialogWidth:880px;DialogHeight=700px;status:no;help:no;resizable:yes;');window.location='#';");

  }

 2、子窗体:


HTML code
  <tr>
                <td class="style3">客户名称:</td>
                <td class="style1">
                    <asp:Label ID="Label3" runat="server" Text="Label3"></asp:Label>
                </td>
            </tr>

C# code
 string IDStr = Request.QueryString["id"].ToString();
OleDbConnection sqlConn = DB.CreateConn();
        sqlConn.Open();
        string sqlStr = "select * from XXXX where F_name='" + IDStr.ToString() + "'";

        OleDbCommand MyCommand = new OleDbCommand(sqlStr, sqlConn);
        OleDbDataReader MyReader = MyCommand.ExecuteReader();
        while(MyReader.Read())
        {
            this.Label3.Text = MyReader["XXX"].ToString();
        }
        sqlConn.Close();

 

 

三、

现在的问题是,父窗体A打开子窗体B,然后子窗体B在打开窗体C(那窗体C就算是窗体B的子窗体了),请问子窗体C该如何向窗体B传值?
1、父窗体A:

this.Button1.Attributes.Add("onclick", "window.showModalDialog('子窗体B.aspx','window','dialogWidth:880px;DialogHeight=600px;status:no;help:no;resizable:yes;');window.location='#';");

2、子窗体B:

<script type="text/javascript">
        function XuanZe()
        {
           window.open('孙子窗体C.aspx','newwindow','height=300,width=500,top='+(screen.AvailHeight-300)/2+',left='+(screen.AvailWidth-300)/2+',toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');
        }
</script>
<asp:TextBox ID="TextBox3" runat="server" Width="200px"></asp:TextBox>
<input id="Button3" type="button" value="选择" onclick="XuanZe()"/>
C# code

TextBox3.Text = Request.QueryString["id"].ToString();
3、孙子窗体C:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //鼠标双击事件
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
           e.Row.Attributes.Add("onDblClick", "javascript:window.opener.location.href='子窗体B.aspx?id="+e.Row.Cells[1].Text.ToString() + "';window.close();");

 

e.Row.Attributes.Add("onDblClick", "javascript:window.opener.documentById('txt').value='"+e.Row.Cells[1].Text.ToString() + "';window.close();");

 
        }
    }


四、用window.open(),window.showModalDialog()打开页面的区别应用

  a.用window.open()打开子窗口的传参方法

  a.html

HTML code

<html>

<body>
要传的值
<input type='text' id='txtID' name='txtName' value='aa' /> <br>
<input type='button' value='open' onclick="window.open('b.html');" />

<script>
alert('刷新了页面');
function method()
{
    alert('a.html');
}
</script>
</body>
</html>


b.html

HTML code

<html>
<script>
function getValue()
{
    //document.getElementById('txt').value=window.opener.txtName.value;
        document.getElementById('txt').value=window.opener.document.getElementById('txtID').value;
}
</script>
<body onload='getValue();'>
传过来的值是
<input type='text' id='txt' />
<input type='button' value='调用父窗口的方法' onclick='window.opener.method();' />
<br>
<br>
<br>
设置父窗口的文本<input type='text' id='t' />
<input type='button' value='执行'
onclick='window.opener.document.getElementById("txtID").value=document.getElementById("t").value;' />
<br>
<br>
<input type='button' value='刷新父窗口' onclick='window.opener.location=window.opener.location;' />
<br>
<br>
<input type='button' value='关闭父窗口' onclick='window.opener.close();opener=null;' />
</body>
</html>
b,用window.showModalDialog()打开窗口的传参方法c.htmlHTML code
<html>
<script>
function getValue()
{
    if(window.dialogArguments)
        {
          document.getElementById('txt').value=window.dialogArguments.document.getElementById('txtID').value;    
        }
       
}
</script>
<body onload='getValue();'>
传过来的值是
<input type='text' id='txt' />
<input type='button' value='调用父窗口的方法' onclick='window.dialogArguments.method();' />
<br>
<br>
<br>
设置父窗口的文本<input type='text' id='t' />
<input type='button' value='执行'
onclick='window.dialogArguments.document.getElementById("txtID").value=document.getElementById("t").value;' />
<br>
<br>
<input type='button' value='刷新父窗口' onclick='window.dialogArguments.location=window.dialogArguments.location;' />
<br>
<br>
<input type='button' value='关闭父窗口' onclick='window.dialogArguments.close();' />
</body>
</html>