首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从gridview RowCommand调用Javascript函数

从gridview RowCommand调用Javascript函数
EN

Stack Overflow用户
提问于 2012-11-08 12:50:59
回答 3查看 8.3K关注 0票数 2

有人知道如何在ASP中从Gridview RowCommand事件中调用Javascript函数吗?

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

谢谢

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-11-08 13:24:54

您可以使用ScriptManager调用它

代码语言:javascript
复制
ScriptManager.RegisterStartupScript(this, this.GetType(), "myalert", "alert('File already exists.');", true);

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

票数 1
EN

Stack Overflow用户

发布于 2012-11-08 13:53:20

代码语言: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 ... 
        }
    }
票数 2
EN

Stack Overflow用户

发布于 2012-12-18 15:15:54

如果你想调用一个JavaScript函数,这可能会对你有所帮助。

Page.ClientScript.RegisterStartupScript(this.GetType(),“调用我的函数”,"func()",true);

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13282618

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档