从gridview行命令调用Javascript函数

从gridview行命令调用Javascript函数,javascript,asp.net,Javascript,Asp.net,有人知道如何在ASP中从Gridview行命令事件调用Javascript函数吗 我需要调用函数来接收rowindex,但我不知道如何从rowcommand调用javascript函数 谢谢您可以使用ScriptManager调用它 ScriptManager.RegisterStartupScript(this, this.GetType(), "myalert", "alert('File already exists.');", true); 您可以调用javascript函数来代替警报

有人知道如何在ASP中从Gridview行命令事件调用Javascript函数吗

我需要调用函数来接收rowindex,但我不知道如何从rowcommand调用javascript函数


谢谢

您可以使用ScriptManager调用它

ScriptManager.RegisterStartupScript(this, this.GetType(), "myalert", "alert('File already exists.');", true);

您可以调用javascript函数来代替警报。

如果您想调用javascript函数,这可能会对您有所帮助

protected void myGV_RowCommand(Object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "click1")
        {
           GridViewRow gvr = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);

           int RowIndex = gvr.RowIndex; 
           // now call the javascript function
           Page.ClientScript.RegisterStartupScript(this.GetType(), "modalDialog", "CallJavaScriptFunction("+RowIndex +");", true);
        }

        if (e.CommandName == "click2")
        {
            Do something cool ... 
        }
    }
Page.ClientScript.RegisterStartupScript(this.GetType(),“调用我的函数”,“func()”,true)

只需将func替换为函数名


如果您在脚本中使用jquery,请不要忘记添加源jquery文件。

检查答案。……我收到了以下消息:无法将类型为“Xxx.XXXXX.Classes.GridViewTemplate.ExtendedGridView”的对象强制转换为类型为“System.Web.UI.WebControls.ImageButton”@ZenIskan有什么异常吗?这些对象似乎有问题(ImageButton)我没有使用按钮模板。我正在使用extendedGridView模板中的编辑:您应该有一个按钮或链接来单击它,它将进入RowCommand事件。用ImageButton替换按钮或链接。我在给你举个例子