2

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 rowcommand

Thanks

0

3 Answers 3

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 ... 
        }
    }
Sign up to request clarification or add additional context in comments.

4 Comments

i got this message : Unable to cast object of type 'Xxx.XXXXX.Classes.GridViewTemplate.ExtendedGridView' to type 'System.Web.UI.WebControls.ImageButton'
@ZenIskan what is the exception??
seem problem with these (imagebutton) i didn't use button template. i'm using edit in extendedGridView template : pastebin.com/YHQzYDAS
You should have a button or link to click which goes u into the RowCommand event. Replace your button or link with ImageButton. I was giving you the example
1

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.