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

Radgrid Update command false notification

4 Answers 75 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Subhashini
Top achievements
Rank 1
Subhashini asked on 28 Oct 2014, 09:10 PM
Hi,

I am new to Telerik. I am trying to update the db with the help of the example provided Grid - RadToolBar as Command Item here  -http://demos.telerik.com/aspnet-ajax/toolbar/examples/applicationscenarios/gridcommanditem/defaultvb.aspx?product=grid , I removed the functions using quickstart, no delete, no insert. Just the  update function.

When I click on the Update button, it gives the message as updated "id updated", but it is not updated in the database.

//After so many tries this is the updated command that worked without errors like Oracle invalid table name or missing expression. Parameter = '@Parameter'

here is my sqlsource for update command

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServicesOracle %>"

ProviderName="<%$ ConnectionStrings:ApplicationServicesOracle.ProviderName %>"

UpdateCommand="update PM_table set COMET_DESCRIPTOR = '@COMET_DESCRIPTOR', COMET_TRANS_NOTES ='@COMET_TRANS_NOTES' where id= '@id' and year||month='@year||'@month'">

<UpdateParameters>

<asp:Parameter Name="COMET_DESCRIPTOR" Type="String" ></asp:Parameter>

<asp:Parameter Name="COMET_TRANS_NOTES" Type="String" ></asp:Parameter>

<asp:Parameter Name="year" Type="String" ></asp:Parameter>

<asp:Parameter Name="month" Type="String" ></asp:Parameter>

<asp:Parameter Name="id" Type="String" ></asp:Parameter>

</UpdateParameters>

</asp:SqlDataSource

>

codebehind .vb

Protected Sub RadGrid1_ItemUpdated(ByVal source As Object, ByVal e As Telerik.Web.UI.GridUpdatedEventArgs) Handles RadGrid1.ItemUpdated

If Not e.Exception Is Nothing Then

e.KeepInEditMode = True

e.ExceptionHandled = True

DisplayMessage(True, "id " + e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("id").ToString() + " cannot be updated due to invalid data. " + e.Exception.ToString)

Else

DisplayMessage(False, "id " + e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("id").ToString() + " updated")

 

End If
End Sub


 

 

 


4 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 31 Oct 2014, 01:25 PM
Hello Subahshini,

I revise the provided code, but I'm not completely sure what is the exact issue you are facing and if it still remains on your end. Does adding the proper parameters fix  the problem or you still need help for achieving the required functionality.
In case further assistance is needed, please elaborate a bit more on the exact issue you are facing, and what the current configuration if the controls is, so that we could do our bets to provide you the assistance.

Regards,
Maria Ilieva
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, 04:42 PM
Thank yo so much for your reply. I tried with the editform radgrid and was able to update successfully. But I am trying to do it with edit mode="batch"; I couldn't reterieve the values from the edit template. All it fetches is the value from the itemtemplate.
Here is the code:
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">
<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>
<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:
Protected Sub RadGrid1_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs)
Dim editedItem As GridEditableItem = TryCast(e.Item, GridEditableItem)
Dim firm_code As String = editedItem.OwnerTableView.DataKeyValues(editedItem.ItemIndex)("FIRM_CODE").ToString()
Dim yr As String = editedItem.OwnerTableView.DataKeyValues(editedItem.ItemIndex)("REF_YY").ToString()
Dim mon As String = editedItem.OwnerTableView.DataKeyValues(editedItem.ItemIndex)("REF_MM").ToString()
Dim desc, notes As String
Try
If TypeOf e.Item Is GridDataItem Then
Dim editItem As GridDataItem = CType(e.Item, GridDataItem)
desc = (TryCast(editItem("COMET_DESCRIPTOR").Controls(0), DropDownList)).SelectedValue.ToString
notes = (TryCast(editItem("COMET_TRANS_NOTES").Controls(0), TextBox)).Text.ToString
'Couldn't get the values. It always says nothing - object null reference
'Update Query to update the Datatable
End If
Catch ex As Exception
RadGrid1.Controls.Add(New LiteralControl("Unable to update firm code. Reason: " + ex.Message))
e.Canceled = True
End Try
End Sub
0
Maria Ilieva
Telerik team
answered on 04 Nov 2014, 08:35 AM
Hi,

Note that when the RadGrid is in batch editing mode it uses only one editor for a single column. All editors are rendered in a hidden panel and are only visible when a cell/row is opened for edit. Accessing these editors and the panel which holds them is achievable by calling the GetBatchColumnEditor or GetBatchEditorContainer methods of the GridTableView which take as an argument the column or it's UniqueName. A sample demonstration on how to call the mentioned methods is provided in the help topic below:
http://www.telerik.com/help/aspnet-ajax/grid-batch-editing.html

Regards,
Maria Ilieva
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 05 Nov 2014, 03:55 PM
Thank you Maria. I will try this and let you know.
Tags
Grid
Asked by
Subhashini
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Subhashini
Top achievements
Rank 1
Share this question
or