GridView中有一列,有onclick事件,想点击此列,即可关闭页面,并把值传给父页。       代码如下:
  <asp:TemplateField HeaderText="账号">
            <ItemTemplate>
            <a href="#"  onclick="javascript:getpick1('<%# Eval("USER_Account")%>')"   > <%# Eval("USER_Account")%> </a> 
            </ItemTemplate>
            </asp:TemplateField>
js 函数: <script   type="text/jscript" >
 
function getpick1(strname) {
  window.opener.Var_Account.value = strname
  self.close();
    }
 
  </script>
发现无法触发onclick事件。
请大侠排忧解难,非常感谢!

解决方案 »

  1.   

    链接的 onclick 事件被先执行,其次是 href 属性下的动作(页面跳转,或 javascript 伪链接)
    假设链接中同时存在 href 与 onclick,如果想让 href 属性下的动作不执行,onclick 必须得到一个 false 的返回值
      

  2.   

    大叔生性愚拙,请多指教。“如果想让 href 属性下的动作不执行,onclick 必须得到一个 false 的返回值 ”
    怎么弄?大叔是asp页面转化为asp.net的,不晓得有这一坎。
      

  3.   

                <a href="#"  onclick="javascript:getpick1('<%# Eval("USER_Account") %>');return false;"    > <%# Eval("USER_Account")%> </a> 
    加上 return false 也不行呀。
      

  4.   

    function getpick1(strname) { 
    alert('strname');
      window.opener.Var_Account.value = strname 
      self.close(); 触发了啊 你的意思是不是传不到父窗体的值?
      

  5.   

    <a href="javascript:函数名">
      

  6.   

    哈哈 还是用window.open吧 我刚试了下
    parent 也是不好使。
    你看看这个行不行 父页面一个连接到子页面 下面是子页面
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><!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  type="text/jscript" language="javascript" > function getpick1(strname)
     { 
      window.open("Default2.aspx?ID1="+strname);
      //window.parent.opener.document.getElementById("name").value =strname;
     self.close(); 
    }  </script> 
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
            <Columns>
            <asp:TemplateField HeaderText="账号"> 
                <ItemTemplate> 
                <a href="#"  onclick="javascript:getpick1(' <%# Eval("UsersID")%>')" ><%# Eval("UsersName")%></a> 
                </ItemTemplate> 
                </asp:TemplateField>         </Columns>
            </asp:GridView>
        </div>
        </form>
    </body>
    </html>
     protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("UsersID");
            dt.Columns.Add("UsersName");
            DataRow dr = dt.NewRow();
            dr[0] = "1234";
            dr[1] = "1";
            dt.Rows.Add(dr);
            this.GridView1.DataSource = dt;
            this.GridView1.DataBind();
            
        }
      

  7.   

    还有个问题 呵呵 你贴的代码中
    <a href="#"  onclick="javascript:getpick1(' <%# Eval("USER_Account")%>')"  > <%# Eval("USER_Account")%> </a> <%# Eval("USER_Account")%>前面是不是多个空格啊!
      

  8.   


            function getpick1(strName)
            {
                window.returnValue=strName;
                window.opener=null;
                window.close();
            }
      

  9.   

    在 
    RowDataBound里 
    e.Row.Attributes.Add("onDblClick", "javascript:window.opener.location.href='子窗体B.aspx?id="+e.Row.Cells[1].Text.ToString() + "';window.close();"); 
    e.Row.Attributes.Add("onDblClick", "javascript:window.opener.documentById('txt').value='"+e.Row.Cells[1].Text.ToString() + "';window.close();"); 
    http://topic.csdn.net/u/20091020/16/b3e78af2-add8-422f-a2ae-67dd58c33a84.html
      

  10.   


        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("ondblclick", "window.open('ParticularInfo.aspx?id=" + e.Row.Cells[0].Text + "')");//双击行打开新页
                ((LinkButton)(e.Row.Cells[3].Controls[0])).Attributes.Add("onclick","return confirm('确定要删除吗?')");//确定删除消息提示
                e.Row.Cells[2].Text = DateTime.Parse(e.Row.Cells[2].Text).ToString("yyyy-MM-dd");//格式化日期
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=\"" + e.Row.Style["BACKGROUND-COLOR"] + "\"");//鼠标随行而变色
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor=\"" + "#9FACCF" + "\"");//鼠标随行而变色
            }
        }
    自己拿去改。
      

  11.   

    改为
                 window.opener.document.form1["Var_Account"].value=strname;
                 window.close();
    就实现了。谢谢大家!