您的位置:首页 > Web前端 > JavaScript

js怎么在弹出的子窗体中将DataGrid选中的某行值传回给父窗体

2007-06-21 21:46 274 查看
/* frmChild.aspx */

//弹出子窗口先绑定
this.datagrid1.DataBind();

//循环做事件
for(int i=0;i<this.datagrid1.Items.Count;i++)
{
str = this.datagrid1.Items[i].Cells[0].Text + "|" + this.datagrid1.Items[i].Cells[1].Text;
this.datagrid1.Items[i].Attributes.Add("onclick","foo('" + str + "');");
}

这样,点击每一行的时候,就会发生一个事件.再在脚本中写:
function foo(strRetValue)
{
window.returnValue = strRetValue;//传回给frmParent.aspx的字符串值
self.close();
}

如此,就把第1列及第2列值取回来了

如果让子窗口不开新窗口,加上base target="_self">即可.不支持IE5.0

/* frmParent.aspx */

function open()

{

var strRetValue=window.showModalDialog('frmChild.aspx?val=' + document.all('TextBox1').value + ',window,'dialogWidth:470px;dialogHeight:300px;scroll:no;center:yes;help:no;resizable:no;status:no');

document.all('TextBox1').value=strRetValue;//得到frmChild.aspx中传回来的值



//var strArr=strRetValue;//如果要将返回值转成数组
//var arr=strArr.split("|");
// alert(arr[0]); alert(arr[1]); ......



}

<a href="javasrcript:open();"> click to select data from datagrid1</a>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: