Telerik - EditMode="InPlace" example

This is an example of how to code Insert/Update/Delete using a Telerik RadGrid

 

<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" 
CodeFile="OEDSecurity.aspx.vb" Inherits="admin_OEDSecurity" %> <asp:Content ID="Content1" ContentPlaceHolderID="header" Runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">         <div class="title1">             Group Form Permissions</div>     <asp:DropDownList ID="ddlGroup" runat="server" AutoPostBack="true"></asp:DropDownList><br /><br />     <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False"          EditMode="InPlace" CommandItemDisplay="Top"         CssClass="grid" Skin="Web20"         AllowPaging="True" PageSize="20"  Width="600px"         >         <MasterTableView DataKeyNames="lRowID" CommandItemDisplay="Top" EditMode="InPlace">             <Columns>                  <telerik:GridButtonColumn ConfirmText="Delete this user?" ConfirmDialogType="RadWindow"                     ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" ConfirmDialogHeight="100px"                     ConfirmDialogWidth="220px"  />                 <telerik:GridEditCommandColumn   ButtonType="ImageButton"></telerik:GridEditCommandColumn>                 <telerik:GridBoundColumn Visible="false" DataField="LRowID"  ></telerik:GridBoundColumn>                 <telerik:GridBoundColumn Visible="false" DataField="sObjectName" ></telerik:GridBoundColumn>                 <telerik:GridBoundColumn HeaderText="Section" DataField="col1" ReadOnly="true" ></telerik:GridBoundColumn>                 <telerik:GridBoundColumn HeaderText="Form" DataField="col2" ReadOnly="true" ></telerik:GridBoundColumn>                 <telerik:GridBoundColumn HeaderText="Permissions" DataField="intPerms" ></telerik:GridBoundColumn>             </Columns>         </MasterTableView>     </telerik:RadGrid> </asp:Content>

 

Code Behind:

Imports Telerik.Web.UI
  
Partial Class admin_OEDSecurity
    Inherits InheritedPage
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'set up the grid
  
        If Not IsPostBack Then
            buildCombo()
            Me.RadGrid1.Rebind()
        End If
  
    End Sub
  
    Sub buildCombo()
        Me.ddlGroup.DataSource = dynData.SPs._4P_OEDGroups_SEL(AppUser.strLastDB).getTable
        Me.ddlGroup.DataValueField = "lRowID"
        Me.ddlGroup.DataTextField = "sGroupName"
        Me.ddlGroup.DataBind()
        Dim li As New ListItem("Choose a Group", 0)
        li.Selected = True
        Me.ddlGroup.Items.Add(li)
  
    End Sub
  
  
    Protected Sub ddlGroup_SelectedIndexChanged
(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlGroup.SelectedIndexChanged
        Session("GroupID") = Me.ddlGroup.SelectedValue
        Me.RadGrid1.Rebind()
    End Sub
  
    Protected Sub RadGrid1_DeleteCommand
(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.DeleteCommand
        Dim intUserID As Int32 = TryCast(e.Item, GridDataItem).GetDataKeyValue("intUserID")
        If Not IsNumeric(Session("GroupID")) Then
            Response.Redirect("~/admin/adminmenu.aspx")
        End If
  
        SPIntranet.sp_4P_userGroup_DEL_userFromGroup(intUserID, Session("GroupID")).execute()
  
    End Sub
  
    Protected Sub RadGrid1_InsertCommand
(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.InsertCommand
        Dim strUserName As String = ""
        Dim insertedItem As GridDataInsertItem = DirectCast(e.Item, GridDataInsertItem)
        strUserName = (TryCast(insertedItem("vchrUserName").Controls(0), TextBox)).Text
  
    End Sub
  
    Protected Sub RadGrid1_UpdateCommand
(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand
        Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
 
        'get an item from the grie
        Dim strProjectName As String = ""
        strProjectName = (TryCast(editedItem("ProjectName").Controls(0), TextBox)).Text
 
        'get one of the data key values
        Dim intRowID As Int32 = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("RowID").ToString()
 
 
        Dim o As New DynData.FPProject(intRowID, AppUser.strLastDB)
        o.ProjectName = strProjectName
        o.Save(AppUser.strLastDB)
 
        Me.RadGrid1.Rebind()
  
    End Sub
  
    Protected Sub RadGrid1_NeedDataSource
(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
        Dim intGroupID As Int16 = Session("GroupID")
        Me.RadGrid1.DataSource = dynData.SPs.FP_Hierarchy_SEL(intGroupID, AppUser.strLastDB).getTable
  
    End Sub
  
    Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object,
ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound
        'code to hide the 'edit' command button
        If TypeOf e.Item Is GridDataItem Then
            Dim item As GridDataItem = e.Item
  
            Dim lnkButton As ImageButton = item("EditCommandColumn").Controls(0)
  
            'the 'save' button is labeled 'insert'
            If Not lnkButton.AlternateText = "Insert" Then
                lnkButton.Visible = False
            End If
        End If
    End Sub
  
End Class

RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences