【急】动态获取window.open()后的窗口中GridView中行的数据【之后续问题】 本帖最后由 yinyuan1987 于 2009-09-12 11:00:53 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 对4个textbox赋值时,4个都获取到值,而且弹出窗口也正常关闭了吗? 能获取到值,也能关闭,但是在弹出窗口的其他事件不能相应了只对一个textBox赋值可以使用,2个以上就不可以了 试一试这两种方法1. 在调用方写一个script函数,由被调用方调用调用方:<script language="javascript">function assignToTB(QRFNoVal, CustVal) { var QRFNo = document.getElementById('QRFNo'); QRFNo.value = QRFNoVal; var CustCode = document.getElementById('Customer'); CustCode.value = CustVal; } </script> 被调用方:<script language="javascript">function ReturnValue(QRFNo, CustCode) { self.opener.assignToTB(QRFNo, CustCode); self.close(); return false; } </script>2.在被调用方试一试下面的格式:Function close(value){window.opener.document.forms[0].TextBox1.value = value;window.close();}参考:http://forums.asp.net/p/1361735/2814234.aspx 首先谢谢楼上朋友的回答第一种方法在对我情况不适合,我是在GridView行内数据绑定里定义的,也就是在后台Code里的第二种方法我加上了forms[0]之后,还是一样 你把Open窗口的代码贴出来看看,我在机子上试过的,没有问题。 protected void gvMessageEmp_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //设置行颜色 e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='lightblue'"); //添加自定义属性,当鼠标移走时还原该行的背景色 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c"); //实现双击某一行后,动态更新工资页面的信息; Session["SelectEmpID"] = e.Row.Cells[0].Text.ToString().Trim(); Session["SelectEmpName"] = e.Row.Cells[1].Text.ToString().Trim(); Session["SelectDepID"] = e.Row.Cells[2].Text.ToString().Trim(); Session["SelectDepName"] = e.Row.Cells[3].Text.ToString().Trim(); string jsString = "window.opener.document.getElementById('txtEmpId').value='" + Session["SelectEmpID"] + "';window.opener.document.getElementById('txtEmpName').value='" + Session["SelectEmpName"] + "';window.opener.document.getElementById('txtDepId').value='" + Session["SelectDepID"] + "';window.opener.document.getElementById('txtDepName').value='" + Session["SelectDepName"] + "';window.close();"; e.Row.Attributes.Add("ondblclick", jsString); } } protected void imgbtnSearch_Click(object sender, ImageClickEventArgs e) { string empId = txtEmpID.Text.Trim(); int depId = Convert.ToInt32(ddlDepart.SelectedValue); DataSet ds = new DataSet(); if (empId != "" && empId != null) { ds = HRH_MessageEmpManager.GetHRH_MessageEmp(empId, depId); } else { ds = HRH_MessageEmpManager.GetHRH_MessageEmp(depId); } gvMessageEmp.DataSourceID = null; gvMessageEmp.DataSource = ds; gvMessageEmp.DataBind(); }页面上就只有一个TextBox让用户输入员工编号和一个下拉列表选择部门还有一个查询按钮,就是想点击查询按钮显示相应的记录 你的txtEmpName有没有runat=server的?如果是服务器控件,用txtEmpName在js里找应该是找不到的,要用ClientID 呵呵,现在txtEmpName都可以的获取值,就是open出来窗口的其他事件没法响应 imgbtnSearch_Click事件不执行,事件是否丢失 private BibdData(){string empId = txtEmpID.Text.Trim(); int depId = Convert.ToInt32(ddlDepart.SelectedValue); DataSet ds = new DataSet(); if (empId != "" && empId != null) { ds = HRH_MessageEmpManager.GetHRH_MessageEmp(empId, depId); } else { ds = HRH_MessageEmpManager.GetHRH_MessageEmp(depId); } gvMessageEmp.DataSourceID = null; gvMessageEmp.DataSource = ds; gvMessageEmp.DataBind();} protected void imgbtnSearch_Click(object sender, ImageClickEventArgs e) { BindData();}protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindData(); } } <ItemTemplate><tr><td align="center" onclick="javascript:SetValue('<%# Eval("Id")%>','<%#Eval("Name")%>','<%#Eval("DeptID")%>','<%#Eval("DeptName")%>')" style="cursor: pointer; cursor: hand;" onmouseover="b_on(this)" onmouseout="b_off(this)"><%#Eval("Name")%></td></tr></ItemTemplate> var p_window; if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) p_window = window.parent.opener; else p_window = window.parent.opener; function b_on(target) { color = "lightblue"; target.style.borderColor = "black"; target.style.backgroundColor = color; target.style.color = "white"; } function b_off(target) { target.style.backgroundColor = ""; target.style.borderColor = ""; target.style.color = ""; target.style.fontWeight = ""; } function SetValue(id, name, deptid,deptname) { p_window.document.getElementById("txtEmpId").value = id; p_window.document.getElementById("txtEmpName").value =name; p_window.document.getElementById("txtDeptId").value = deptid; p_window.document.getElementById("txtDeptName").value = deptname; self.close(); } 是的,open出的窗口的其他事件都不执行后台代码有事件的相关处理代码 谢谢wuyq11,我先试试修改代码 呵呵,谢谢大家的回复,问题解决了,是get和post 请求方法的问题默认使用的get,四个参数放在请求头中,数据量太大了把form 的method改为post就OK了! asp.net/.cs文件中如何给.aspx的TextBox添加一个onkeyup的事件 关于ISS上的水晶报表问题 如何默认创建子目录的应用程序池 比撒尿还急^-^^-^^-^vs2003中删除iis目录问题 请大师级人物进来,帮忙看看,非常感谢大家~`````` Internal Server Error大家帮忙看一下 请问有没有办法把.net自带日历控件中的星期一....改为 一 二 三 四 五 六 日? 一个Ctrl+Enter的问题 合并datatable 求后台和类的写法。 请教WAP C#如何解压文件
只对一个textBox赋值可以使用,2个以上就不可以了
1. 在调用方写一个script函数,由被调用方调用调用方:
<script language="javascript">
function assignToTB(QRFNoVal, CustVal) {
var QRFNo = document.getElementById('QRFNo');
QRFNo.value = QRFNoVal;
var CustCode = document.getElementById('Customer');
CustCode.value = CustVal;
}
</script> 被调用方:
<script language="javascript">
function ReturnValue(QRFNo, CustCode)
{
self.opener.assignToTB(QRFNo, CustCode);
self.close();
return false;
}
</script>2.在被调用方试一试下面的格式:
Function close(value){window.opener.document.forms[0].TextBox1.value = value;window.close();}参考:
http://forums.asp.net/p/1361735/2814234.aspx
protected void gvMessageEmp_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//设置行颜色
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='lightblue'"); //添加自定义属性,当鼠标移走时还原该行的背景色 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c"); //实现双击某一行后,动态更新工资页面的信息;
Session["SelectEmpID"] = e.Row.Cells[0].Text.ToString().Trim();
Session["SelectEmpName"] = e.Row.Cells[1].Text.ToString().Trim();
Session["SelectDepID"] = e.Row.Cells[2].Text.ToString().Trim();
Session["SelectDepName"] = e.Row.Cells[3].Text.ToString().Trim(); string jsString = "window.opener.document.getElementById('txtEmpId').value='" + Session["SelectEmpID"] + "';window.opener.document.getElementById('txtEmpName').value='" + Session["SelectEmpName"] + "';window.opener.document.getElementById('txtDepId').value='" + Session["SelectDepID"] + "';window.opener.document.getElementById('txtDepName').value='" + Session["SelectDepName"] + "';window.close();";
e.Row.Attributes.Add("ondblclick", jsString);
}
}
protected void imgbtnSearch_Click(object sender, ImageClickEventArgs e)
{
string empId = txtEmpID.Text.Trim();
int depId = Convert.ToInt32(ddlDepart.SelectedValue); DataSet ds = new DataSet();
if (empId != "" && empId != null)
{
ds = HRH_MessageEmpManager.GetHRH_MessageEmp(empId, depId);
}
else
{
ds = HRH_MessageEmpManager.GetHRH_MessageEmp(depId);
} gvMessageEmp.DataSourceID = null;
gvMessageEmp.DataSource = ds;
gvMessageEmp.DataBind();
}
页面上就只有一个TextBox让用户输入员工编号
和一个下拉列表选择部门
还有一个查询按钮,就是想点击查询按钮显示相应的记录
如果是服务器控件,用txtEmpName在js里找应该是找不到的,要用ClientID
{
string empId = txtEmpID.Text.Trim();
int depId = Convert.ToInt32(ddlDepart.SelectedValue); DataSet ds = new DataSet();
if (empId != "" && empId != null)
{
ds = HRH_MessageEmpManager.GetHRH_MessageEmp(empId, depId);
}
else
{
ds = HRH_MessageEmpManager.GetHRH_MessageEmp(depId);
} gvMessageEmp.DataSourceID = null;
gvMessageEmp.DataSource = ds;
gvMessageEmp.DataBind();
}
protected void imgbtnSearch_Click(object sender, ImageClickEventArgs e)
{
BindData();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData(); }
}
<tr>
<td align="center" onclick="javascript:SetValue('<%# Eval("Id")%>','<%#Eval("Name")%>','<%#Eval("DeptID")%>','<%#Eval("DeptName")%>')" style="cursor: pointer; cursor: hand;" onmouseover="b_on(this)" onmouseout="b_off(this)"><%#Eval("Name")%></td>
</tr>
</ItemTemplate>
var p_window;
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
p_window = window.parent.opener;
else
p_window = window.parent.opener;
function b_on(target) {
color = "lightblue";
target.style.borderColor = "black";
target.style.backgroundColor = color;
target.style.color = "white"; }
function b_off(target) {
target.style.backgroundColor = "";
target.style.borderColor = "";
target.style.color = "";
target.style.fontWeight = "";
}
function SetValue(id, name, deptid,deptname) {
p_window.document.getElementById("txtEmpId").value = id;
p_window.document.getElementById("txtEmpName").value =name;
p_window.document.getElementById("txtDeptId").value = deptid;
p_window.document.getElementById("txtDeptName").value = deptname;
self.close();
}
后台代码有事件的相关处理代码