您所要做的就是将模板列内 LinkButton 的 CommandName 属性设置为“编辑”以进行编辑,“删除”以进行删除,“更新”以进行更新。这将分别触发 GridView RowEditing、RowDeleting 和 RowUpdating 事件。要触发 RowCommand 事件,您需要设置 GridView 控件的 OnRowCommand 属性。
<asp:GridView ID="GridView1" runat="server" OnRowCommand="GridView1_RowCommand"
OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<!--To fire the OnRowEditing event.-->
<asp:LinkButton ID="lbEdit" runat="server" CommandName="Edit"
Text="Edit">
</asp:LinkButton>
<!--To fire the OnRowDeleting event.-->
<asp:LinkButton ID="lbDelete" runat="server" CommandName="Delete"
Text="Delete">
</asp:LinkButton>
<!--To fire the OnRowUpdating event.-->
<asp:LinkButton ID="lbUpdate" runat="server" CommandName="Update"
Text="Update">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>