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

Not updating the database - RadGrid1_UpdateCommand

7 Answers 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Subhashini
Top achievements
Rank 1
Subhashini asked on 29 Oct 2014, 05:09 PM
How do I update using RadGrid1_UpdateCommand for the below example.
http://demos.telerik.com/aspnet-ajax/toolbar/examples/applicationscenarios/gridcommanditem/defaultvb.aspx?product=grid

The values are updated in the radgrid but not to the database.

Protected Sub RadGrid1_UpdateCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand

'If e.CommandName = RadGrid.UpdateCommandName Then

If e.CommandName = "UpdateEdited" Then

If TypeOf e.Item Is GridDataItem Then

Dim editItem As GridDataItem = CType(e.Item, GridDataItem)

Dim id As String = editItem.GetDataKeyValue("FIRM_CODE").ToString()

If id IsNot Nothing Then

                    //I am stuck here. How do I fetch the values for COMET_DESCRIPTOR and COMET_TRANS_NOTES

 

Dim UpdateCommand As String = "update tablename set COMET_DESCRIPTOR = '@COMET_DESCRIPTOR', COMET_TRANS_NOTES ='@COMET_TRANS_NOTES' where FIRM_CODE = '" & id & "' and REF_YY||REF_MM ='@REF_YY'||'@REF_MM'"

End If

End If

End If

End Sub

7 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 03 Nov 2014, 02:35 PM
Hi,

In order to get the new values you need to access the controls that are used for editors and retrieve their values. The approach for accessing cells in RadGrid is illustrated in the following article. Check out the Accessing the Value of Cells in Edit Mode section.


Regards,
Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Subhashini
Top achievements
Rank 1
answered on 03 Nov 2014, 06:44 PM
Thank you for your reply. I tried accesisng the value but I still couldn't access the edited values. In vb, I tried both griditem and grideditableitem. I couldn't read the values. Dunno what I am missing. I have copied the aspx and vb code here.

aspx:
<form id="form1" runat="server">
<telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
<%--<telerik:RadAjaxPanel runat="server" ID="radPanel">--%>
<telerik:RadListBox runat="server" ID="SavedChangesList" Width="600px" Height="200px"
Visible="false">
</telerik:RadListBox>
<telerik:RadGrid ID="RadGrid1" runat="server" GridLines="Both" AllowAutomaticDeletes="true"
AllowAutomaticInserts="true" PageSize="10" Skin="Default" AllowAutomaticUpdates="false"
OnUpdateCommand="RadGrid1_UpdateCommand" AllowPaging="True" AutoGenerateColumns="False"
Width="750px" OnNeedDataSource="RadGrid1_NeedDataSource">
<MasterTableView DataKeyNames="FIRM_CODE,REF_YY,REF_MM" CommandItemDisplay="Bottom"
AllowAutomaticDeletes="true" AllowAutomaticInserts="true" AllowAutomaticUpdates="true"
HorizontalAlign="Left" EditMode="Batch"><%-- DataSourceID="SqlDataSource1"--%>
<BatchEditingSettings OpenEditingEvent="Click" EditType="Cell" />
<SortExpressions>
<telerik:GridSortExpression FieldName="firm_name" SortOrder="Ascending" />
</SortExpressions>
<Columns>
<telerik:GridBoundColumn DataField="closing" HeaderStyle-Width="10px" HeaderText="CLOSING"
UniqueName="closing" ReadOnly="true" Visible="false">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="DESCRIPTOR" HeaderStyle-Width="100px" UniqueName="COMET_DESCRIPTOR">
<ItemTemplate>
<asp:Label runat="server" ID="lblDesc" Text='<%# Eval("COMET_DESCRIPTOR") %>'></asp:Label>
</ItemTemplate>
<%--<%# Eval("COMET_DESCRIPTOR")%>--%>
<EditItemTemplate>
<asp:DropDownList runat="server" ID="dropDescriptor" Width="50">
<Items>
<asp:ListItem Text="" />
<asp:ListItem Text="*" />
<asp:ListItem Text="**" />
<asp:ListItem Text="***" />
<asp:ListItem Text="****" />
</Items>
</asp:DropDownList>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="firm_name" HeaderStyle-Width="210px" HeaderText="Firm Name"
SortExpression="firm_name" UniqueName="firm_name" ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="FIRM_CODE" HeaderStyle-Width="150px" HeaderText="Firm Code"
UniqueName="FIRM_CODE" ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="EXPRECCOUNT" HeaderStyle-Width="100px" HeaderText="Export Count"
UniqueName="EXPRECCOUNT" ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="EXP_DATE" HeaderStyle-Width="150px" HeaderText="Export Date"
UniqueName="EXP_DATE" ReadOnly="true">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn DataField="COMET_TRANS_NOTES" HeaderStyle-Width="210px"
HeaderText="Comet Notes" UniqueName="COMET_TRANS_NOTES">
<ItemTemplate>
<%# Eval("COMET_TRANS_NOTES") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox Width="210px" runat="server" ID="txtNotes">
</asp:TextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="REF_YY" HeaderStyle-Width="210px" HeaderText="Year"
UniqueName="REF_YY" Visible="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="REF_MM" HeaderStyle-Width="210px" HeaderText="Month"
UniqueName="REF_MM" Visible="false">
</telerik:GridBoundColumn>

</Columns>
</MasterTableView>
<ClientSettings AllowKeyboardNavigation="true">
</ClientSettings>
</telerik:RadGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServicesOracle %>"
ProviderName="<%$ ConnectionStrings:ApplicationServicesOracle.ProviderName %>">

</asp:SqlDataSource>

</form>

aspx.vb:
RadGrid1_UpdateCommand:
If TypeOf e.Item Is GridDataItem Then
Dim editItem As GridDataItem = CType(e.Item, GridDataItem)
Dim d As TableCell = editItem("COMET_DESCRIPTOR")
Dim n As TableCell = editItem("COMET_TRANS_NOTES")
Dim dd As String = editItem("COMET_DESCRIPTOR").Text '""
Dim nn As String = editItem("COMET_TRANS_NOTES").Text '""
Dim edited As GridEditableItem = CType(e.Item, GridEditableItem)
Dim ddd As DropDownList = CType(edited.FindControl("COMET_DESCRIPTOR"), DropDownList)
Dim nnn As TextBox = CType(edited.FindControl("COMET_TRANS_NOTES"), TextBox)
Dim des As String = ddd.SelectedValue.ToString 'Object reference not set to an instance of an object.
Dim note As String = nnn.Text.ToString
 
desc = (TryCast(editItem("COMET_DESCRIPTOR").Controls(0), DropDownList)).SelectedValue.ToString
notes = (TryCast(editItem("COMET_TRANS_NOTES").Controls(0), TextBox)).Text.ToString
'Update Query to update the Datatable
End If
0
Viktor Tachev
Telerik team
answered on 06 Nov 2014, 02:36 PM
Hello,

I examined the provided code and noticed that Batch Edit mode is used for RadGrid. Note that in this mode the new values can be retrieved on the server like shown in the following code snippet.

Protected Sub RadGrid1_UpdateCommand(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs)
    Dim argument As GridBatchEditingEventArgument = TryCast(e.CommandArgument, GridBatchEditingEventArgument)
    Dim oldValues As Hashtable = argument.OldValues
    Dim newValues As Hashtable = argument.NewValues
    Dim newFirstName As String = newValues("FirstName").ToString()
End Sub

If you would like additional information regarding Batch Edit mode you would find the following article interesting:


Regards,
Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Subhashini
Top achievements
Rank 1
answered on 26 Mar 2015, 04:47 PM
I am  not sure whether it is the right method but it worked.

<BatchEditingSettings EditType="Cell"

 

 

/>

OnBatchEditCommand

 

 

="RadGrid1_BatchEditCommand"

<telerik:GridTemplateColumn HeaderText="ASSIGNED_TO" HeaderStyle-Width="150px" UniqueName="ASSIGNED_TO"

DataField="ASSIGNED_TO">

<ItemTemplate>

<%# Eval("ASSIGNED_TO")%>

</ItemTemplate>

<EditItemTemplate>

<telerik:RadDropDownList runat="server" ID="ASSIGNED_TODropDown" DataValueField="teamlead"

DataTextField="teamlead" DataSourceID="SqlDataSource2">

</telerik:RadDropDownList>

</EditItemTemplate>

</telerik:GridTemplateColumn>

Vb code:

Protected Sub RadGrid1_BatchEditCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridBatchEditingEventArgs) Handles RadGrid1.BatchEditCommand

For Each command As GridBatchEditingCommand In e.Commands

Dim newAssign As Hashtable = command.NewValues

Dim oldAssign As Hashtable = command.OldValues

fips_code = newAssign("FIPS_CODE").ToString

state = newAssign("STATE").ToString

newAssgn = newAssign("ASSIGNED_TO").ToString

sql = "update tblassignment set ASSIGNED_TO = '" & newAssgn & "' where FIPS_CODE = '" & fips_code & "' and STATE = '" & state & "'"

 

 

Next

End Sub


 

 

 

0
Viktor Tachev
Telerik team
answered on 27 Mar 2015, 10:13 AM
Hi,

The approach you are using is also possible. In the BatchEditCommand event handler you have control over all commands that will be fired. You can also modify the commands collection by adding removing or modifying commands.

Regards,
Viktor Tachev
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Subhashini
Top achievements
Rank 1
answered on 27 Mar 2015, 08:04 PM
Thanks Viktor. By modify the command collections, you mean like the demo here - http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/commanditem/defaultvb.aspx?show-source=true
0
Viktor Tachev
Telerik team
answered on 30 Mar 2015, 03:51 PM
Hello,

The demo you are referring to illustrates how you can define a CommandItemTemplate.

The Commands collection can be accessed in the BatchEditingCommand handler. The e.Commands is a List of GridBatchEditingCommand objects. You can iterate and modify the items in that collection.

Check out the following article that describes the Batch Editing functionality in more detail:




Regards,
Viktor Tachev
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
Grid
Asked by
Subhashini
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Subhashini
Top achievements
Rank 1
Share this question
or