【问题标题】:How to set value of a Parent GridView control from PopUp?如何从 PopUp 中设置父 GridView 控件的值?
【发布时间】:2013-10-01 06:12:33
【问题描述】:

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

父页面

 <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);   

    }

【问题讨论】:

标签: c# javascript asp.net gridview


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-21
    • 1970-01-01
    • 2011-08-20
    • 2010-10-18
    • 1970-01-01
    相关资源
    最近更新 更多