本文介绍了从子窗口到父窗口的值传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个父窗口,其中包含一个文本框和输入按钮控件.子窗口包含Gridview控件和文本框.

每当我从子窗口的gridview中选择记录时,我都希望将值从子窗口传递到父窗口.从gridview控件中选择记录后,必须关闭子窗口和子窗口.

在我的代码中,我将参数从父窗口传递给子窗口.

这是我的代码:

父窗口:

Hi all,

I have a parent window contains a Textbox and input button controls. And child window contains a Gridview control & Textbox.

I want to pass the value from the child window to parent window whenever I select the record from the gridview of the child window. and child window must be closed after select the record from the gridview control.

In my code I am passing the parameter from parent to child window.

Here is my Code:

Parent Window:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head  runat="server">
    <title>Parent Window</title>
    <script type="text/javascript" language="javascript">
    function showChildWin()
    {
       var MyValue=document.getElementById('txt_name').value;
       var myUrl = 'Popup.aspx?myVal='+MyValue;
         window.showModalDialog(myUrl,'My APPs','status:no; dialogWidth:630px; dialogHeight:420px; help:no; scroll:no; menubar:no; resizable:no');
    }

    </script>
</head>
<body>
    <form id="form1"  runat="server">
    <div style="text-align: center">

    <div style="text-align: center">

        <br />


        <asp:TextBox ID="txt_name" runat="server">
        <br />
        <br />
        <br />
        <input id="Button1" type="button"  önclick="showChildWin()" value="Open Child Window" /></div>

        <br />

    </div>
    </form>
</body>
</html>



子窗口:



Child Window:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head  runat="server">
    <title>Child Window</title>
    <script language="javascript" type="text/javascript">

    </script>

</head>
<body>
    <form id="form1"  runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <contenttemplate>


    <div style="text-align: center">

        <br />
        <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" AllowPaging="true" 

            GridLines="None" Height="67px" 

            style="font-family: Verdana; font-size: 10pt" 

            onselectedindexchanged="GridView1_SelectedIndexChanged" Width="345px">
            <columns>
            <asp:CommandField ShowSelectButton="true"/>


            </columns>
            <rowstyle backcolor="#F7F6F3" forecolor="#333333" />
            <footerstyle backcolor="#5D7B9D" font-bold="True" forecolor="White" />
            <pagerstyle backcolor="#284775" forecolor="White" horizontalalign="Center" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <editrowstyle backcolor="#999999" />
            <alternatingrowstyle backcolor="White" forecolor="#284775" />



        <br />
        <br />
        <asp:TextBox ID="TextBox1" runat="server">
        <br />



    </div>
    </contenttemplate>

    </form>
</body>
</html>



子窗口的代码背后:



CodeBehind of Child Window:

protected void Page_Load(object sender, EventArgs e)
        {
            string str_val = Request.QueryString[0].ToString();
            TextBox1.Text = str_val;
            SqlDataAdapter da = new SqlDataAdapter("select address from tblEmpDetails", con);
            DataSet ds = new DataSet();
            da.Fill(ds);
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            TextBox1.Text=GridView1.SelectedRow.Cells[1].Text;
        }





请帮帮我.......

我需要您的尽快帮助.........





Help me please.......

I need your help as soon as possible........

推荐答案




这篇关于从子窗口到父窗口的值传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 13:54
查看更多