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 03 Answers
Reset to default 2protected 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.