This is a migrated thread and some comments may be shown as answers.

radgrid edit,update,delete operations

4 Answers 211 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sreedhar ambati
Top achievements
Rank 1
sreedhar ambati asked on 17 Apr 2011, 06:20 PM
Hi

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?

Regards
Sreedhar

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 18 Apr 2011, 09:24 AM
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

-Shinu.
0
sreedhar ambati
Top achievements
Rank 1
answered on 18 Apr 2011, 04:40 PM
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?

Regards
Sreedhar Ambati
0
Princy
Top achievements
Rank 2
answered on 19 Apr 2011, 05:12 AM
Hello,

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.

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

Thanks,
Princy.
0
abhishek
Top achievements
Rank 1
answered on 16 Aug 2016, 09:16 AM

<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

    Try
        'Open the SqlConnection
        SqlConnection.Open()
        '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
        SqlCommand.ExecuteNonQuery()
        'Close the SqlConnection


        SqlConnection.Close()
    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
Tags
Grid
Asked by
sreedhar ambati
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
sreedhar ambati
Top achievements
Rank 1
Princy
Top achievements
Rank 2
abhishek
Top achievements
Rank 1
Share this question
or