Hi eshant.kapoor...,
Refer the below code.
HTML
<div>
<asp:GridView ID="GridView1" OnRowDataBound="OnRowDataBound" runat="server" AutoGenerateColumns="false"
OnRowCommand="gridData_RowCommand">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Country" HeaderText="Country" />
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:ImageButton ID="btnDelete" runat="server" CommandName="XYZ" AlternateText="Delete" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
Code
Protected Sub Page_Load(sender As Object, e As EventArgs)
If Not Me.IsPostBack Then
Dim dt As New DataTable()
dt.Columns.AddRange(New DataColumn(2) {New DataColumn("Id", GetType(Integer)), New DataColumn("Name", GetType(String)), New DataColumn("Country", GetType(String))})
dt.Rows.Add(1, "John Hammond", "United States")
dt.Rows.Add(2, "Mudassar Khan", "India")
dt.Rows.Add(3, "Suzanne Mathews", "France")
dt.Rows.Add(4, "Robert Schidner", "Russia")
GridView1.DataSource = dt
GridView1.DataBind()
End If
End Sub
Protected Sub OnRowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow AndAlso e.Row.RowIndex <> GridView1.EditIndex Then
Dim btn As ImageButton = TryCast(e.Row.FindControl("btnDelete"), ImageButton)
btn.Attributes("onclick") = "return confirm('Do you want to delete this row?');"
End If
End Sub
Protected Sub gridData_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs)
If e.CommandName = "XYZ" Then
Response.Write("<script type=""text/javascript"">alert(""RowCommand executed"");</script>")
End If
End Sub
Screenshot