It depends on what you want to do ... if you want to process the GridView command, use the OnRowCommand event instead ...
<asp:GridView ID="grid" runat="server" OnRowCommand="grid_RowCommand"> <Columns> <TemplateField> <ItemTemplate> <asp:Button ID="btnFunction1" runat="server CommandName="Delete"/> </ItemTemplate> </TemplateField> </Columns> </asp:GridView>
Then the code behind ...
protected void grid_RowCommand(Object sender, GridViewCommandEventArgs e) { }
But if you just want to handle the button click event, register the event declaratively with the Click event ...
<TemplateField> <ItemTemplate> <asp:Button ID="btnFunction1" runat="server OnClick="Function1"/> </ItemTemplate> </TemplateField>
and configure the event handler method to match the same signature of the Click ... event method
protected void Function1(object sender, EventArgs args) { }
source share