最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net - Call Javascript function from gridview RowCommand - Stack Overflow

programmeradmin0浏览0评论

Does anyone know how to call Javascript functions from a Gridview RowCommand Event in ASP?

i need to call function to receive rowindex but i didn't know how to call javascript function from rowmand

Thanks

Does anyone know how to call Javascript functions from a Gridview RowCommand Event in ASP?

i need to call function to receive rowindex but i didn't know how to call javascript function from rowmand

Thanks

Share Improve this question asked Nov 8, 2012 at 4:50 Zen IskanZen Iskan 1651 gold badge2 silver badges11 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 2
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 ... 
        }
    }

You can call it using ScriptManager

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

In place of alert you can call the javascript function.

If you want to call a JavaScript function this may help you.

Page.ClientScript.RegisterStartupScript(this.GetType(),"Call my function","func()",true);

Just replace func with your function name..

if you use jquery in your script don't forget to add the source jquery file.

发布评论

评论列表(0)

  1. 暂无评论