想双击GridView某行时,通过JS函数调用Button4的Click事件,但是无法成功
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("ondblclick", "rowdata()");
            }
        }
后台Click事件
        protected void Button4_Click(object sender, EventArgs e)
        {
            TextBox1.Text = Button4.ID;
        }
前台JS函数
    <script type="text/javascript">
       function rowdata()
       {
           document.getElementByID("Button4").onclick();
       }
    </script>
请看看哪里不对,document.getElementByID("Button4").onclick()是这样写吗

解决方案 »

  1.   

    你把Button4放到隐藏域里,按钮别设置隐藏
      

  2.   

    直接调用JQuery库,然后
    $(document).ready(function(){
      $("按钮ID").click();
    })
      

  3.   

    <script type="text/javascript">
      function rowdata()
      {
      document.getElementByID("Button4").onclick();
      }
      </script>
    把上面的脚本放在form后面
      

  4.   

    是click,不是onclick
    document.getElementByID("Button4").click();
      

  5.   

    ondblclick?  GridView双击返回 收藏 
    JS:  <script language="javascript" type="text/javascript">        
             function DbClickEvent(d)
             {
                   window.opener.document.getElementById('帐号').value=d;    
                   window.close();        
             }
             function ClickEvent(d)
             {
                   window.alert("事件类型: OnClick   作用对象: " + d);            
             }
             function GridViewItemKeyDownEvent(d)
             {
                   window.alert("事件类型: GridViewItemKeyDownEvent   作用对象: " + d);       
             }
             function KeyDownEvent()
             {
                   if( event.altKey && event.keyCode > 48 && event.keyCode < 54 )            
                    {                
                           window.alert("事件类型: FormKeyDownEvent   选中记录数: " + ( parseInt(event.keyCode) - 48 )); 
                    }                      
             }           
    </script>后台:
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //鼠标移动到每项时颜色交替效果
                e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='White';this.style.color='#003399'");
                e.Row.Attributes.Add("OnMouseOver", "this.style.backgroundColor='#6699FF';this.style.color='#8C4510'");            //单击/双击 事件
                e.Row.Attributes.Add("OnDblClick", "DbClickEvent('" + e.Row.Cells[1].Text + "')");
                //   e.Row.Attributes.Add("OnClick", "ClickEvent('" + e.Row.Cells[1].Text + "')");            e.Row.Attributes.Add("OnKeyDown", "GridViewItemKeyDownEvent('" + e.Row.Cells[1].Text + "')");            //设置悬浮鼠标指针形状为"小手"
                e.Row.Attributes["style"] = "Cursor:hand";        }
        }前台:
    <asp:GridView ID="GridView1" runat="server" BackColor="White" 
                                    BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" 
                                    GridLines="None"  Width="100%" CellSpacing="1" 
                                        onrowdatabound="GridView1_RowDataBound" AllowPaging="True" 
                                        onrowcreated="GridView1_RowCreated" onrowcommand="GridView1_RowCommand">
                                    <FooterStyle BackColor="#C6C3C6" HorizontalAlign="Center" ForeColor="Black" />
                                    <RowStyle BackColor="#ECF4F7" HorizontalAlign="Center" ForeColor="Black" />
                                    <EmptyDataRowStyle BackColor="#E3EBEE" BorderStyle="None" />
                                   
                                    <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
                                    <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
                                    <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" 
                                        HorizontalAlign="Center" />
                                    <EditRowStyle BorderStyle="Dotted" />
                                    <AlternatingRowStyle HorizontalAlign="Center" />
                                </asp:GridView>参考
      

  6.   

    function rowdata(){
       document.getElementByID("<%=Button4.ClientID%>").click();
    }
      

  7.   

    Button4没设置隐藏
    改成document.getElementByID("Button4").click()也无效
    放到form后面也不行
      

  8.   

    没有引用母版页
      <script type="text/javascript">
      function rowdata()
      {
      document.getElementByID("Button4").onclick();
      }
      </script>
    这段是放在head段里的
      

  9.   

    正解,,因为服务器控件生成HTML的时候,ID也是自动生成的,,你要用ClientID获取
      

  10.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="run.aspx.cs" Inherits="jiamei_asp2008.Run.run" %>
    <%@ Register src="runmenu.ascx" tagname="runmenu" tagprefix="uc1" %>
    <%@ Register src="../CustomCalendar.ascx" tagname="CustomCalendar" tagprefix="uc2" %>
    <%@ Register src="../textbox_N0.ascx" tagname="textbox_N0" tagprefix="uc3" %>
    <%@ Register src="../textbox_f2.ascx" tagname="textbox_f2" tagprefix="uc4" %>
    <!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 id="Head1" runat="server">
        <title>无标题页</title>
        <link href="../StyleSheet.css" rel="stylesheet" type="text/css" />
        <style type="text/css">
            #form1
            {
                width: 981px;
            }
            #Text1
            {
                width: 60px;
            }
            #Button4
            {
                height: 23px;
                width: 59px;
            }
        </style>
        <script language="javascript" type="text/javascript" src="../PlugIn/My97DatePicker/WdatePicker.js"></script>
        <script language="javascript" type="text/javascript" src="../PlugIn/JavaScript.js"></script><!--从外部JS文件调用函数-->
        <script type="text/javascript">
           function rowdata()
           {
               document.getElementByID("<%=Button4.ClientID%>").click();
           }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
    .........................
        </form>
        </body>
    </html>
      

  11.   

    document.getElementByID("<%=Button4.ClientID%>").click()这句也不起作用,就用click()吗,后台是protected void Button4_Click(object sender, EventArgs e)事件
      

  12.   

    晕死,我就是要看你的GridView和Button4的aspx代码……
      

  13.   

    是不是因为TextBox1放在一个UpdatePanel里的原因啊,双击的是GridView不是Button4,所以无法刷新Textbox1,怎样添加GridView双击触发UpdatePanel啊
      

  14.   

        <div id="gridview">
            <asp:Panel ID="Panel1" runat="server" BorderStyle="Inset" Height="340px" 
                ScrollBars="Auto" HorizontalAlign="Center">
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:ScriptManager ID="ScriptManager1" runat="server">
                    </asp:ScriptManager>
                    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                DataSourceID="SqlDataSource1" 
        AllowSorting="True" CellSpacing="1" onrowdatabound="GridView1_RowDataBound">
                        <Columns>
                            <asp:TemplateField HeaderText="序号"></asp:TemplateField>
                            <asp:BoundField DataField="bh" HeaderText="编号" ReadOnly="True" 
                        SortExpression="bh" Visible="False" />
                            <asp:BoundField DataField="cpmc" HeaderText="产品名称" SortExpression="cpmc" >
                                <ItemStyle Width="80px" HorizontalAlign="Left" />
                            </asp:BoundField>
                            <asp:BoundField DataField="pp" HeaderText="品牌" SortExpression="pp" >
                                <ItemStyle Width="80px" />
                            </asp:BoundField>
                            <asp:BoundField DataField="gg" HeaderText="规格" SortExpression="gg" >
                                <ItemStyle Width="150px" HorizontalAlign="Left" />
                            </asp:BoundField>
                            <asp:BoundField DataField="jhrq" HeaderText="进货日期" SortExpression="jhrq" 
                                DataFormatString="{0:yyyy.MM.dd}" >
                                <ItemStyle HorizontalAlign="Center" />
                            </asp:BoundField>
                            <asp:BoundField DataField="jhsl" HeaderText="进货数量" SortExpression="jhsl" >
                                <ItemStyle HorizontalAlign="Right" />
                            </asp:BoundField>
                            <asp:BoundField DataField="jhdj" HeaderText="进货单价" SortExpression="jhdj" 
                                DataFormatString="{0:f}" >
                                <ItemStyle HorizontalAlign="Right" Width="80px" />
                            </asp:BoundField>
                            <asp:BoundField DataField="kcsl" HeaderText="库存数量" SortExpression="kcsl" >
                                <ItemStyle HorizontalAlign="Right" />
                            </asp:BoundField>
                            <asp:BoundField DataField="lr" HeaderText="利润" SortExpression="lr" 
                                DataFormatString="{0:f}" >
                                <ItemStyle HorizontalAlign="Right" />
                            </asp:BoundField>
                            <asp:BoundField DataField="xsh" HeaderText="显示" SortExpression="xsh" 
                        Visible="False" />
                            <asp:BoundField DataField="xg" HeaderText="修改" SortExpression="xg" 
                        Visible="False" />
                        </Columns>
                        <HeaderStyle HorizontalAlign="Center" CssClass="gridviewheaderstyle" />
                    </asp:GridView>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
                    <asp:AsyncPostBackTrigger ControlID="Button2" EventName="Click" />
                    <asp:AsyncPostBackTrigger ControlID="Button3" EventName="Click" />
                </Triggers>
            </asp:UpdatePanel>
            </asp:Panel>
            <div>
                <asp:Button ID="Button2" runat="server" Text="保存" CssClass="button" 
                    onclick="Button2_Click" />
                <asp:Button ID="Button3" runat="server" Text="删除" CssClass="button"/>
                <asp:Button ID="Button4" runat="server" CssClass="button" 
                    onclick="Button4_Click" Text="Button" />
            </div>
        </div>
      

  15.   

            <div>
                <asp:Button ID="Button2" runat="server" Text="保存" CssClass="button" 
                    onclick="Button2_Click" />
                <asp:Button ID="Button3" runat="server" Text="删除" CssClass="button"/>
                <asp:Button ID="Button4" runat="server" CssClass="button" 
                    onclick="Button4_Click" Text="Button" />
            </div>
      

  16.   

    把Button4也放到同一个updatePanel里去
      

  17.   

    document.getElementByID("Button4").onclick();
    JS里区分大小的吧!
    getElementByID 改成 getElementById