Telerik ASP.NET Radgrid Delete functionality

body header
Anchor directly to this post Micah 8/12/2011 9:55:39 AM

Adding delete functionality to a Telerik ASP.NET RadGrid is not hard. There are two steps: adding a GridButtonColumn to the grid as shown below; and adding the Delete Command Handler to the code behind. In our example we use a data table stored in the Session as our data source, but this could be easily translated to a stored procedure.

This code also show how to delete from a datatable


Anchor directly to this post Micah 8/12/2011 9:57:14 AM

Add this markup to the grid.

<telerik:RadGrid ID="RadGrid1" ClientInstanceName="RadGrid1" runat="server" AutoGenerateColumns="false"  Skin="Web20" CssClass="grid" >
    <MasterTableView DataKeyNames="lRowID" EditMode="EditForms" CommandItemDisplay="Top" >
            <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                <ItemStyle CssClass="MyImageButton" />
            <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" UniqueName="DeleteColumn">
                <ItemStyle CssClass="MyImageButton" />

Note that we're talking specifically about the last three lines

Add this event handler to the code behind

Protected Sub RadGrid1_DeleteCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.DeleteCommand
    Dim lRowID As String = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("lRowID").ToString()
    Dim oPoDT As New DataTable
    If Session("oPoDT") Is Nothing Then
        Exit Sub
    End If
    oPoDT = Session("oPoDT")
    If Not (oPoDT.Rows.Find(lRowID) Is Nothing) Then
        Session("oPoDT") = oPoDT
    End If
End Sub






Unknown or N/A
.NET Development