0

我有一个 GridView,它有一个控件。LinkButton当我点击这个 LinkBut​​ton(父页面的 GridView)时,我正在打开一个弹出窗口,LinkButtons当我点击这个LinkButton(弹出的 GridView)时,它也有一个 GridView 和一个列。 . 弹出窗口关闭,名称或文本值被传递到父页面.. 我有这么多工作。我不想将我从 PopUp GridView 检索到的这个值设置为LinkButton最初称为 PopUp 的父页面的 GridView。

父页面

 <asp:GridView ID="GridView1" runat="server">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">click</asp:LinkButton>
                    <br />                    
                    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

<script type="text/javascript">
    function FillTextFromPopup(text) {
        alert(text);       
    }
</script>

*父页面的代码在后面 *

protected void Page_Load(object sender, EventArgs e)
    {
        DataTable table = new DataTable();
        table.Columns.Add("Dosage", typeof(int));
        table.Columns.Add("Drug", typeof(string));
        table.Columns.Add("Patient", typeof(string));
        table.Columns.Add("Date", typeof(DateTime));

        table.Rows.Add(25, "Indocin", "David", DateTime.Now);
        table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
        table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
        table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
        table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);

        GridView1.DataSource = table;
        GridView1.DataBind();
    }


    protected void LinkButton1_Click(object sender, EventArgs e)
    {            
            GridViewRow gvRow = (GridViewRow)(sender as Control).Parent.Parent;
            int index = gvRow.RowIndex;
            LinkButton lnk = (LinkButton)gvRow.FindControl("LinkButton1");
            string id = lnk.ID;
            Session["myID"] = id;
            string myScript;
            myScript = "<script>window.open('PopUpTest1.aspx?',null,'height=750, width=1024,status= no,resizable= no, scrollbars=yes,toolbar=no,location=no,menubar=no'); </script>";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "pop", myScript, false);
        }

弹出页面

<asp:GridView ID="GridView1" runat="server">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click1" 
                        Text='<%# Eval("name") %>'></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

弹出页面背后的代码

protected void Page_Load(object sender, EventArgs e)
    {
        DataTable table = new DataTable();
        table.Columns.Add("a", typeof(int));
        table.Columns.Add("b", typeof(string));
        table.Columns.Add("c", typeof(string));
        table.Columns.Add("d", typeof(DateTime));
        table.Columns.Add("name", typeof(string));

        table.Rows.Add(1, "Indocin1", "David1", DateTime.Now,"arbaaz");
        table.Rows.Add(2, "Enebrel1", "Sam1", DateTime.Now,"Ravish");
        table.Rows.Add(3, "Hydralazine1", "Christoff1", DateTime.Now,"Gulzar");
        table.Rows.Add(4, "Combivent1", "Janet1", DateTime.Now,"Anas");
        table.Rows.Add(5, "Dilantin1", "Melanie1", DateTime.Now,"Danish");

        GridView1.DataSource = table;
        GridView1.DataBind();
    }


    protected void LinkButton1_Click1(object sender, EventArgs e)
    {

        GridViewRow gvRow = (GridViewRow)(sender as Control).Parent.Parent;
        int index = gvRow.RowIndex;
        LinkButton lnk = (LinkButton)gvRow.FindControl("LinkButton1");        
        string myScript=lnk.Text;
        string aaa = "javascript:window.opener.FillTextFromPopup('"+myScript+"'); window.close();";
        ScriptManager.RegisterStartupScript(this, GetType(), ClientID, aaa, true);   

    }
4

1 回答 1

0

有两种方法可以更改父页面网格上的某些值。

  1. 只需访问 java 脚本上的父页面 * DOM 元素并更改它。
  2. 另一个是在关闭弹出窗口时使用查询字符串将数据传递到父页面。和父页面的onload你可以改变任何你想要的
于 2013-10-01T08:41:50.140 回答