Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

How to call gridview button click event in java script
Posted

1 solution

Just add the RowDataBound Event to GridView. and palce the specified code inside.

C#
<asp:gridview id="GridView1" runat="server" allowpaging="True" autogeneratecolumns="False" xmlns:asp="#unknown">
 DataKeyNames="ID" DataSourceID="SqlDataSource1" PageSize="15" AllowSorting="True" OnRowDatabound="GridView1_RowDataBound" OnRowCommand = "GridView1_RowCommand" >

protected void GridView1_RowDataBound(object sender, GridViewRowCommandEventArgs e)
{

 if(e.Row.RowIndex != -1)
 {
  //Here Index of Cell will be the No of Delete Column. 
  LinkButton btn = (LinkButton)e.Row.Cells[1].Controls[1];
  btn.Attributes.Add("onclick","if (confirm('Are you sure to delete this admin user?')){return true} else {return false}");
 }
}
 </asp:gridview>


this code is working in my sample gridview..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900