1、父窗体:<td>
  <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
<td>
  <asp:Button ID="Button3" runat="server" Text="选择" OnClientClick="XuanZe()" />
</td>function XuanZe()
  {
    window.open('子窗体.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');  }2、子窗体:
<Columns>
  <asp:BoundField DataField="F_name" HeaderText="编号" />
  <asp:BoundField DataField="F_name" HeaderText="名称" />
  <asp:BoundField DataField="F_cltID" HeaderText="外键"/>
</Columns>//隐藏GridView外键列
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
   e.Row.Cells[2].Visible = false;
}
 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {      //鼠标双击事件
      if (e.Row.RowType == DataControlRowType.DataRow)
     {
        int  QQ =Convert.ToInt32( e.Row.Cells[2].Text.ToString());//拿隐藏列值        e.Row.Attributes.Add("onDblClick", "javascript:window.opener.location.href='父窗体.aspx?id=" + e.Row.Cells[1].Text.ToString() + "';window.close();");
        e.Row.Attributes.Add("onDblClick", "javascript:window.opener.document.getElementById(Textox1).value='" + e.Row.Cells[1].Text.ToString() + "';window.close();");
     } 
  }
现在的问题是:e.Row.Cells[1].Text.ToString()的值可以传过去,但隐藏列的值我已经获取到了,这个该怎么传过去?1、我已经试过e.Row.Attributes.Add("onDblClick", "javascript:window.opener.location.href='父窗体.aspx?id=" + e.Row.Cells[1].Text.ToString() + "&id2="+隐藏列的值+"';window.close();");父窗体Request.QueryString["id2"],不行。PS:Request.QueryString["id2"]为Null。2、同样的在子窗体这边用Session也一样,为Null。请前辈帮忙看下,小弟感激不尽!

解决方案 »

  1.   

    string str="javascript:window.opener.location.href='父窗体.aspx?id=" + e.Row.Cells[1].Text.ToString() + "&id2="+隐藏列的值+"';window.close()";e.Row.Attributes.Add("onDblClick",....把红色放你 e.row.attributes.add(...) 前面去 断点 调试下 就是按 F5 调试  看看 str  的值是什么?
    估计 还是你没取到 隐藏列的值
      

  2.   

    Request.QueryString["id2"]   ??
    我一般都是 直接 request["id2"]  哦
      

  3.   

    e.Row.Attributes.Add("onDblClick", "javascript:window.opener.document.getElementById('TextBox1').value='" + e.Row.Cells[2].Text + "';window.close();");这个我试了一下可以的,TextBox1加个引号的
      

  4.   


    我F9到int  QQ =Convert.ToInt32( e.Row.Cells[2].Text.ToString());//拿隐藏列值
    已经拿到了是 35
      

  5.   

    你照 4 楼 说的去 测试下咯? 我是估计问题还是出在你的URL 传值上
      

  6.   

    e.Row.Attributes.Add("onDblClick", "javascript:window.opener.location.href='aprent.aspx?id=" + e.Row.Cells[2].Text + "';window.close();");这样也可以的,如果你的有问题,估计就是e.Row.Cells[2].Text这个值有问题的
      

  7.   


    对呀, 是可以, 但请看上面,我不但要传e.Row.Cells[1].Text ,还要传e.Row.Cells[2].Text 
      

  8.   

    getElementById('TextBox1')嗯 问题应该出在这里 吧  你在生成的页面 查看原码 看看 父窗口的那个控件的 id 还是 TextBox1 么?
    如果 你 父窗体 的textbox 在 gridview 里面的话 那么它 的 id 是 动态的id 你要另找途径去获得它的ID 
      

  9.   

    这样用url传应该没问题的,仔细调试下,看url里面的值有没有什么问题
      

  10.   

    将隐藏的列改成模板列,用FindControl找到它
    protected void GridView_RowCreated(object sender, GridViewRowEventArgs e) 
        { 
            if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header) 
            { 
                e.Row.Cells[1].Visible = false; 
                e.Row.Cells[2].Visible = false; 
            } 
        } 
    取值: 
    GridView.Rows [i].Cells [1].Text 或 
    <asp:HiddenField ID="Hd_SH" Value=' <%#DataBinder.Eval(Container.DataItem,"BH")%>' runat="server" /> 
    或 
      <asp:BoundField DataField="BH" HeaderText=""> 
    <ControlStyle CssClass="hidden" /> 
    <FooterStyle CssClass="hidden"/> 
    <HeaderStyle CssClass="hidden"/> 
    <ItemStyle CssClass="hidden"/> 
    </asp:BoundField> 
    .hidden 

    display:none; 

      

  11.   


    你还没明白,我在说下:   e.Row.Attributes.Add("onDblClick", "javascript:window.opener.location.href='父窗体.aspx?id=" + e.Row.Cells[1].Text.ToString() + "';window.close();");
            e.Row.Attributes.Add("onDblClick", "javascript:window.opener.document.getElementById(Textox1).value='" + e.Row.Cells[1].Text.ToString() + "';window.close();");
    这个值可以传过去,父窗体那边可以拿到,我是说: 我还想在把隐藏列的值也传过去,该怎么办?2楼说我 问个问题还写那么多代码...    我不写那么多 描述不清楚啊
      

  12.   

    wuyq11 大哥 我试下啊先谢过
      

  13.   


    这问题我碰到过哦 我就是这么解决的
    关于textbox 的动态ID问题 就是 textbox1.clientID 这就是 textbox1 的动态 ID了 
      

  14.   


    现在的问题是:传一个值过去,怎么都好说
    我想传两个值呢?该怎么办?
    难道e.Row.Attributes.Add("onDblClick", "javascript:window.opener.location.href='父窗体.aspx?id=" + e.Row.Cells[1].Text.ToString() + "';window.close();");
            e.Row.Attributes.Add("onDblClick", "javascript:window.opener.document.getElementById(Textox1).value='" + e.Row.Cells[1].Text.ToString() + "';window.close();");e.Row.Attributes.Add("onDblClick", "javascript:window.opener.location.href='父窗体.aspx?id=" + e.Row.Cells[2].Text.ToString() + "';window.close();");
            e.Row.Attributes.Add("onDblClick", "javascript:window.opener.document.getElementById(Textox1).value='" + e.Row.Cells[2].Text.ToString() + "';window.close();");
      

  15.   


    你好 我曾经 这么去找 隐藏列的 值 但是 找部到哦 ? 是怎么回事?
    我一度认为隐藏的东西就是不可操作的东西  就像 我隐藏了textbox 后就操作不了它了
    在这里借机请教了!!LZ 不好意思啊 我审错题了 哦
      

  16.   

    GridView.Rows [i].Cells [1].Text 
     的话 也可以拿到 应该设置GridView的DataKeyNames应该可以我没试过那
      

  17.   

    在一条语句里写或调用
    window.opener里function
      

  18.   

    子窗体
    写脚本:
    function f(var1,var2,var3)
    {
    window.op.....;
    window.op.....;
    }然后你C#后台代码写:
    e.row.attributes.add(".....","f(.....)");var1 var2 var3 是 控件ID 哦
      

  19.   

    window.opener.getElementById(\""+var1+"\").value="+var2+";
    window.opener.getElementById(\""+var3+"\").value="+var4+";e.row.attributes.add("ondblclick","f("+var1+","+var2+","+var3+","+var4")");
      

  20.   

    获取一行,selectedRow, 可以把它作为参数传到别的窗体,但是目的地窗体的构造函数的参数要是gridviewrow类型的。
    然后获取这一行的相应单元格的值
      

  21.   


    还没好,报错了
    function QQ(TextBox1,TBContractAnnalName,var2,var3)
          {
              window.opener.getElementById(\""+TextBox1+"\").value="+var2+";
               window.opener.getElementById(\""+TBContractAnnalName+"\").value="+var3+";  
                //window.close();
           }
    你确定 这个转义字符没错嘛  我这报错了
    [/code]你给我说下 这四个参数都代表什么意思?。
      

  22.   

    像 你上面那么写的 textbox1  TBContractAnnalName  是父窗口的控件ID, 而 var2 var3 就是你要传给父窗口的值咯。
    你说报错? 报什么错哦?
      

  23.   


    textbox1 TBContractAnnalName 是父窗口传到子窗口来的哦!!你可以同过URL传过来给子窗口,你必须保证你的ID 是正确的ID gridveiw 里面嵌入的控件的ID 是动态的,你可不能直接拿来用的。父窗口:
    string strTextBox1ID=TextBox1.ClientID; //获取TextBox1的动态ID.
    Response.Write("xxx.aspx?textbox1id="+strTextBox1ID+","子窗口名字","子窗口设定");
    子窗口:
    C#后台代码:(
    e.row.attributes.add("ondblclick","window.document.getElementById(\""+Request["textbox1id"]+"\").value='"+你要传给父窗口的值 str +"'");
      

  24.   

    问题都处在这:window.opener.getElementById(\""+TextBox1+"\").value="+var2+"; 
              window.opener.getElementById(\""+TBContractAnnalName+"\").value="+var3+"; 
    未定义字符:16行
    我目前还没找到估计是转义字符那块
      

  25.   

    父窗口:
    asp 代码:
    <asp:TemplateField HeaderText="產品名稱">
                            <ItemTemplate>
                                <asp:Label ID="Label8" runat="server" Text='<%# Eval("ProductName") %>'></asp:Label>
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Right" Width="120px" />
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("ProductName") %>'
                                    Width="90px"></asp:TextBox><asp:Button ID="Button5" runat="server" Height="23px" CommandName ="<%# Container.DataItemIndex %>"
                                        Text="..." OnClick="Button5_Click" />

                            </EditItemTemplate>
                        </asp:TemplateField>
    这是我父窗口中gridview控件中绑定的模版列中的一小段代码,用LABEL 绑定字段 ProductName 编辑模版列里有一个TEXTBOX BUTTON 请注意看 BUTTON 的代码。
    C#后台代码:
    protected void Button5_Click(object sender, EventArgs e)
        {
            Button btn = sender as Button;
            int i = int.Parse(btn.CommandName);
            GridViewRow row = gridviewOrd.Rows[i];

            string s2 = row.Cells[2].Controls[1].ClientID;
            Response.Write("<script>window.open('getP.aspx?txtid=" + s2 + "','getP','height=350,width=450,top=200,left=300,alwaysRaised=no,dependent=yes,location=no,menubar=no,resizable=no,titlebar=no,boolbar=no');</script>");
        }
    蓝色部分获取 点击 按钮 所在的行号,红色 获取 TEXTBOX BUTTON 中TEXTBOX 的 动态ID ,再后面就是打开子窗口代码 里面有URL 传值。
    至于 在 gridview_RowDataBind() 中又要如何写,你可以自己借鉴下参考着 应该可以写出来了。子窗口:
    C#后台代码:
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#ccccff'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
                e.Row.Attributes.Add("ondblclick", "window.opener.document.getElementById(\"" + Request["txtbcid"] + "\").value='" + e.Row .Cells [1].Text +
                                        "';window.opener.document.all.form1.hid.value='" + e.Row .Cells [0].Text + "';window.close();"
    );
            }
        }子窗口里 我用的也是一个gridview 把双击行的值传给父窗口控件中 ,就是我上面贴的 TEXTBOX 中去
      

  26.   

    谢谢你  你还没明白我的意思...我现在子窗口(双击)向父窗口传值没问题,已经可以的(发帖前都可以的)问题是:我(双击GridView)要传两个值过去父窗口那边有两个TextBox在等着拿值....
      

  27.   

    昨天这种方法 我试了下  老报错  
    function QQ(TextBox1,TBContractAnnalName,var2,var3) 
          { 
             window.opener.getElementById(\""+TextBox1+"\").value="+var2+"; 
              window.opener.getElementById(\""+TBContractAnnalName+"\").value="+var3+"; 
                //window.close(); 
          } 偶恨JavaScript差劲...
      

  28.   

    e.Row.Attributes.Add("ondblclick", "window.opener.document.getElementById(\"" + Request["txtbcid"] + "\").value='" + e.Row .Cells [1].Text + 
                                        "';window.opener.document.all.form1.hid.value='" + e.Row .Cells [0].Text + "';window.close();"就这样啊; 里面连着写window.opener....啊 ; 来隔开他们
    要是太长了的话, 在外面 string str ="...." 在 e.row.attributes.add("...",str); 咯
      

  29.   

    结贴
    太搞笑了搞了我半天就是连着写window.opener....
    准备重修JavaScript.