Reputation: 165
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
Upvotes: 2
Views: 9185
Reputation: 1938
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.
Upvotes: 0
Reputation: 19282
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 ...
}
}
Upvotes: 2
Reputation: 1161
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.
Upvotes: 1