我有一个 GridView,它有一个控件。LinkButton
当我点击这个 LinkButton(父页面的 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);
}