radgrid edit,update,delete operations

5 posts, 0 answers
  1. sreedhar ambati
    sreedhar ambati avatar
    36 posts
    Member since:
    Aug 2009

    Posted 17 Apr 2011 Link to this post


    I have a radgrid and I am binding the grid from codebehind using stored procedure.
    I want edit ,delete images on each row.
    On click of edit I should be able all the cells of that row.on delete it should delete the record.
    can u just give me one sample?

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 18 Apr 2011 Link to this post

    Hello Sreedhar,

    Please take a look at the following Code Library which explains how to perform insert/update/delete operations from code behind.
    Manual Insert/Update/Delete operations using Auto-generated editform with sql statements from the code-behind:
    Manual Insert/Update/Delete using FormTemplate and Sql backend

  3. DevCraft R3 2016 release webinar banner
  4. sreedhar ambati
    sreedhar ambati avatar
    36 posts
    Member since:
    Aug 2009

    Posted 18 Apr 2011 Link to this post

    Thanks for the demo.
    In the header I am getting Add New Record link.
    I am not having inserting new record functionality.How to make it invisible?

    In the examples given after clicking on edit link it is displaying in a separate div or table.
    but i want in the same row of edit link.

    Can you help me in this?

    Sreedhar Ambati
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Apr 2011 Link to this post


    If you don't want 'AddNewRecord' functionality in RadGrid, you can set CommandItemDisplay property of MasterTableView as None.
    And in order to show the edit row in same line, set EditMode  as InPlace.

    <MasterTableView CommandItemDisplay="None" EditMode="InPlace">

  6. abhishek
    abhishek avatar
    2 posts
    Member since:
    Aug 2016

    Posted 16 Aug Link to this post

    <telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" runat="server" Skin="Lime" GridLines="None" AllowPaging="True"AllowSorting="True" AutoGenerateColumns="False" Width="97%" OnUpdateCommand="RadGrid1_UpdateCommand"><PagerStyle Mode="NextPrevAndNumeric"></PagerStyle><MasterTableView DataKeyNames="EmployeeID" GridLines="None" Width="100%" CommandItemDisplay="Top"><Columns><telerik:GridBoundColumn DataField="EmployeeID" HeaderText="EmployeeID" UniqueName="EmployeeID"ReadOnly="True"></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="LastName" HeaderText="LastName" UniqueName="LastName"></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="FirstName" HeaderText="FirstName" UniqueName="FirstName"></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="Title" HeaderText="Title" UniqueName="Title"></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="Address" HeaderText="Address" UniqueName="Address"></telerik:GridBoundColumn><telerik:GridBoundColumn DataField="City" HeaderText="City" UniqueName="City"></telerik:GridBoundColumn><telerik:GridEditCommandColumn></telerik:GridEditCommandColumn></Columns><EditFormSettings CaptionDataField="EmployeeID"><FormTableItemStyle Wrap="False"></FormTableItemStyle><FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle><FormMainTableStyle CellSpacing="0" CellPadding="3" Width="100%" /><FormTableStyle GridLines="Horizontal" CellSpacing="0" CellPadding="2" CssClass="module"Height="110px" Width="100%" /><FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle><FormStyle Width="100%" BackColor="#EEF2EA"></FormStyle><EditColumn UpdateText="Update record" UniqueName="EditCommandColumn1" CancelText="Cancel edit"></EditColumn><FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle></EditFormSettings><ExpandCollapseColumn Visible="False"><HeaderStyle Width="19px"></HeaderStyle></ExpandCollapseColumn><RowIndicatorColumn Visible="False"><HeaderStyle Width="20px" /></RowIndicatorColumn></MasterTableView></telerik:RadGrid>



    VB Code-

    Public Shared dtTable As DataTable
    'Get the connectionstring from the webconfig and declare a global SqlConnection "SqlConnection"
    Public Shared connectionString As String = ConfigurationManager.AppSettings("ConnectionString")
    Public SqlConnection As New SqlConnection(connectionString)
    'Declare a global SqlDataAdapter SqlDataAdapter
    Public SqlDataAdapter As New SqlDataAdapter()
    'Declare a global SqlCommand SqlCommand
    Public SqlCommand As New SqlCommand()

    Protected Sub RadGrid1_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs)
        'Get the GridEditableItem of the RadGrid
        Dim editedItem As GridEditableItem = TryCast(e.Item, GridEditableItem)
        'Get the primary key value using the DataKeyValue.
        Dim EmployeeID As String = editedItem.OwnerTableView.DataKeyValues(editedItem.ItemIndex)("EmployeeID").ToString()
        'Access the textbox from the edit form template and store the values in string variables.
        Dim LastName As String = (TryCast(editedItem("LastName").Controls(0), TextBox)).Text
        Dim FirstName As String = (TryCast(editedItem("FirstName").Controls(0), TextBox)).Text
        Dim Title As String = (TryCast(editedItem("Title").Controls(0), TextBox)).Text
        Dim Address As String = (TryCast(editedItem("Address").Controls(0), TextBox)).Text
        Dim City As String = (TryCast(editedItem("City").Controls(0), TextBox)).Text

            'Open the SqlConnection
            'Update Query to update the Datatable
            Dim updateQuery As String = "UPDATE Employees set LastName='" & LastName & "',FirstName='" & FirstName & "',Title='" & Title & "',Address='" & Address & "',City='" & City & "' where EmployeeID='" & EmployeeID & "'"
            SqlCommand.CommandText = updateQuery
            SqlCommand.Connection = SqlConnection
            'Close the SqlConnection

        Catch ex As Exception
            RadGrid1.Controls.Add(New LiteralControl("Unable to update Employee. Reason: " + ex.Message))
            e.Canceled = True
        End Try

    End Sub

    I am using above code but getting error like specified arguement out of range of valid values parameter name :index
Back to Top
DevCraft R3 2016 release webinar banner