如何从弹出式窗体的父窗体下拉列表中添加值? [英] How to add value to parent form drop down list from popup form?

查看:70
本文介绍了如何从弹出式窗体的父窗体下拉列表中添加值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请让我知道我在做什么错了?

我使用了以下代码.

在弹出页面中

">%

@ 页面 语言 ="C#" AutoEventWireup ="true" CodeFile ="Country.aspx.cs" >继承 ="Country" %>

> <!

DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR /xhtml1/DTD/xhtml1-transitional.dtd".

> html xmlns ="http://www.w3.org/1999/xhtml"

> head runat ="server"

> title ></ 标题

> 脚本 语言 ="javascript">

">

功能 GetRowValue(val)

">

">

var ddl = window.opener. document.getElementById( "cbRegCountry" );

">

var optn = document.createElement( "OPTION" );

">

ddl.options [ddl.options.length +1] = optn;

"> optn.text =

"dsds"

optn.value = 1;

window.close();

}

</

脚本 >

</

正文 >

">

< form id ="form1" runat =服务器">

">

> asp > SqlDataSource ID ="SqlDataSource1" runat =服务器"

">

ConnectionString =" <%$ ConnectionStrings:ConnectionString%> >"

">

ProviderName =" <%$ ConnectionStrings:ConnectionString.ProviderName%> >"

">

SelectCommand =="SELECT国家/地区名称" FROM TBL_Country" />

">

> asp > GridView ID ="GridView1" runat =服务器" DataSourceID ="SqlDataSource1" OnRowDataBound ="GridView1_RowDataBound">

">

> >

">

> asp > TemplateField >

">

> AlternatingItemTemplate >

">

> asp > 按钮 ID ="btnSelect" runat =服务器" 文本 ="Select" />

">

>/ AlternatingItemTemplate >

">

> ItemTemplate >

">

> asp > 按钮 ID ="btnSelect" runat =服务器" 文本 ="Select" />

">

</ ItemTemplate >

">

</ asp : TemplateField >

">

</ >

</

 

asp:GridView>

 

</form>

</

 

body>

</

 

html>

The Parent page code for the button click

protected

 

void btnMoreCountry_Click(object sender, EventArgs e)

{

 

if (IsPostBack)

{

 

this.btnMoreCountry.Attributes.Add("onclick", "javascript:return PopupCountry()");

}

}

 

解决方案

Hi,

Hope below line will be helpful. Below line of code you can write on window close of popup window event or any button click of popup window event.

window.opener.parent.Form1['ANY CONTROL'].value=YOUR VALUE

此致

Hitendra


Hi,

 I need to add items to parent forms drop down list from popup page. Popup page has a gridview and in gridview beside each row there is a select button. On click of select button the text should come and add in the parent page drop down list from popup page. By my code it just add one empty string in the drop down list.

Please let me know what am i doing wrong here?

I used the below code.

In Pop up page

<%

@ Page Language="C#" AutoEventWireup="true" CodeFile="Country.aspx.cs" Inherits="Country" %>

<!

 

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title></title>

<script language="javascript">

 

function GetRowValue(val)

{

 

var ddl = window.opener.document.getElementById("cbRegCountry");

 

var optn = document.createElement("OPTION");

 

ddl.options[ddl.options.length + 1] = optn;

optn.text =

"dsds";

optn.value = 1;

window.close();

}

</

 

script>

</

 

head>

 

body>

 

<form id="form1" runat="server">

 

<asp:SqlDataSource ID="SqlDataSource1" runat="server"

 

ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

 

ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"

 

SelectCommand="SELECT CountryName FROM TBL_Country" />

 

<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound">

 

<Columns>

 

<asp:TemplateField>

 

<AlternatingItemTemplate>

 

<asp:Button ID="btnSelect" runat="server" Text="Select" />

 

</AlternatingItemTemplate>

 

<ItemTemplate>

 

<asp:Button ID="btnSelect" runat="server" Text="Select" />

 

</ItemTemplate>

 

</asp:TemplateField>

 

</Columns>

</

 

asp:GridView>

 

</form>

</

 

body>

</

 

html>

The Parent page code for the button click

protected

 

void btnMoreCountry_Click(object sender, EventArgs e)

{

 

if (IsPostBack)

{

 

this.btnMoreCountry.Attributes.Add("onclick", "javascript:return PopupCountry()");

}

}

 

解决方案

Hi,

Hope below line will be helpful. Below line of code you can write on window close of popup window event or any button click of popup window event.

window.opener.parent.Form1['ANY CONTROL'].value=YOUR VALUE

Regards,

Hitendra


这篇关于如何从弹出式窗体的父窗体下拉列表中添加值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆