开发者

How to delete a GridView Row

开发者 https://www.devze.com 2023-01-29 17:30 出处:网络
I have this code until now: 开发者_高级运维<asp:TemplateField ShowHeader=\"False\" ItemStyle-Width=\"150px\" HeaderStyle-BackColor=\"#003ca1\" HeaderStyle-ForeColor=\"white\">

I have this code until now:

开发者_高级运维<asp:TemplateField ShowHeader="False" ItemStyle-Width="150px" HeaderStyle-BackColor="#003ca1" HeaderStyle-ForeColor="white">
    <ItemTemplate>
        <asp:LinkButton ID="linkDelete" runat="server" CausesValidation="False" CommandName="Delete" OnClientClick='return confirm("Diesen Eintrag wirklich löschen?");' Text="Löschen" />
    </ItemTemplate>
</asp:TemplateField>

At this moment, the GridView deletes the row physically. I want to catch this in CodeBehind, cancel the delete-operation and want only set a "IsDeleted"-Flag in the database.

How?


You can use the RowDeleting event and the Cancel property of the GridViewDeleteEventArgs object to do this. Here is what the MSDN page says:

The RowDeleting event is raised when a row's Delete button is clicked, but before the GridView control deletes the row. This enables you to provide an event-handling method that performs a custom routine, such as canceling the delete operation, whenever this event occurs.

A GridViewDeleteEventArgs object is passed to the event-handling method, which enables you to determine the index of the current row and to indicate that the delete operation should be canceled. To cancel the delete operation, set the Cancel property of the GridViewDeleteEventArgs object to true. You can also manipulate the Keys and Values collections, if necessary, before the values are passed to the data source.

0

精彩评论

暂无评论...
验证码 换一张
取 消