PDA

View Full Version : [CLOSED] Server side delete on GridPanel CommandColumn



marco.morreale
May 23, 2012, 8:17 AM
Hi,
when CommandColumn button is pressed, event should be handled server side where I call the web service to delete the record from the db.

I am trying to accomplish that but event "HandleChanges" server-side function is not firing.

Moreover, I'm getting the following error when i specify AutoSync="true":
Message":"Il tipo \u0027System.Collections.Generic.IDictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]\u0027 non è supportato per la deserializzazione di una matrice.","StackTrace":" in System.Web.Script.Serialization.ObjectConverter.Co nvertListToObject(IList list, Type type, JavaScriptSerializer serializer, Boolean throwOnError, IList& convertedList)\r\n in System.Web.Script.Serialization.ObjectConverter.Co nvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n in System.Web.Script.Serialization.ObjectConverter.Co nvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n in System.Web.Script.Serialization.JavaScriptSerializ er.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n in System.Web.Script.Serialization.JavaScriptSerializ er.Deserialize[T](String input)\r\n in System.Web.Script.Services.RestHandler.GetRawParam sFromPostRequest(HttpContext context, JavaScriptSerializer serializer)\r\n in System.Web.Script.Services.RestHandler.GetRawParam s(WebServiceMethodData methodData, HttpContext context)\r\n in System.Web.Script.Services.RestHandler.ExecuteWebS erviceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}

Is there a bettere way to accomplish my task?
After deleting I should handle editing, and addCommentLine, also.
Thanks in advance
M


.aspx



<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="BasketRows.ascx.cs" Inherits="renosistemi.it.Controls.BasketRows" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<ext:GridPanel
ID="gpBasket"
runat="server"
Width="800"
Height="400"
Frame="true"
Title="Carrello"
>
<Store>
<ext:Store ID="stBasket" runat="server" PageSize="10" RemotePaging="false" OnBeforeStoreChanged="HandleChanges" AutoSync="true" >
<Proxy>
<ext:AjaxProxy Json="true" Url="../WebServices/AjaxWebService.asmx/getBasketLines">
<ActionMethods Read="POST" />
<Reader>
<ext:JsonReader Root="d.Data" TotalProperty="d.Total" />
</Reader>
</ext:AjaxProxy>
</Proxy>
<Parameters>
<ext:StoreParameter Name="basketID" Value="1" Mode="Value" />
</Parameters>
<Model>
<ext:Model runat="server" IDProperty="Line">
<Fields>
<ext:ModelField Name="Line" Mapping="Line" Type="int" />
<ext:ModelField Name="Codice" Mapping="Codice" Type="string" />
<ext:ModelField Name="Descrizione" Mapping="Descrizione" Type="string" />
<ext:ModelField Name="Cilindro" Mapping="Cilindro" />
<ext:ModelField Name="Asse" Mapping="Asse" />
<ext:ModelField Name="Potere" Mapping="Potere" />
<ext:ModelField Name="Quantity" Mapping="Quantity" Type="Int" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<Plugins>
<ext:RowEditing runat="server" ClicksToMoveEditor="1" AutoCancel="false" ClicksToEdit="1" />
</Plugins>
<ColumnModel>
<Columns>
<ext:RowNumbererColumn runat="server" Width="25" />
<ext:Column runat="server"
Text="Codice"
DataIndex="Codice"
Width="110">
</ext:Column>
<ext:Column runat="server" Text="Descrizione" DataIndex="Descrizione" Flex="1">
</ext:Column>
<ext:NumberColumn
runat="server"
Text="Cilindro"
DataIndex="Cilindro"
Width="70" Align="Right">
</ext:NumberColumn>
<ext:Column runat="server" Text="Asse" DataIndex="Asse" >
</ext:Column>
<ext:NumberColumn
runat="server"
Text="Potere"
DataIndex="Potere"
Width="70" Align="Right">
</ext:NumberColumn>
<ext:NumberColumn
runat="server"
Text="Quantità"
DataIndex="Quantity"
Width="70"
Format="0" Align="Right" >
<Editor>
<ext:NumberField
runat="server"
AllowBlank="false"
MinValue="0"
MaxValue="9999"
Step="1"
AllowDecimals="false"
DecimalPrecision="0"
/>
</Editor>
</ext:NumberColumn>
<ext:CommandColumn runat="server" Width="60">
<Commands>
<ext:GridCommand Icon="Bin" CommandName="Delete">
<ToolTip Text="Elimina la riga" />
</ext:GridCommand>
<ext:CommandSeparator />
<ext:GridCommand Icon="NoteAdd" CommandName="AddNote">
<ToolTip Text="Aggiungi una nota" />
</ext:GridCommand>
</Commands>
<Listeners>
<Command Handler="#{gpBasket}.store.remove(record);" />
</Listeners>
</ext:CommandColumn>
</Columns>
</ColumnModel>
<BottomBar>
<ext:PagingToolbar runat="server" />
</BottomBar>
</ext:GridPanel>



.cs




protected void HandleChanges(object sender, BeforeStoreChangedEventArgs e)
{
//List<TestPerson> persons = e.DataHandler.ObjectData<TestPerson>();

//if (e.Action == StoreAction.Create)
//{
// foreach (TestPerson created in persons)
// {
// this.AddPerson(created);
// e.ResponseRecords.Add(created);
// }
//}

//if (e.Action == StoreAction.Destroy)
//{
// foreach (TestPerson deleted in persons)
// {
// this.DeletePerson(deleted.Id.Value);
// //e.ResponseRecords.Add(new {});
// }
//}

//if (e.Action == StoreAction.Update)
//{
// foreach (TestPerson updated in persons)
// {
// this.UpdatePerson(updated);
// e.ResponseRecords.Add(updated);
// }
//}
e.Cancel = true;
}

Daniil
May 23, 2012, 12:38 PM
Hi,

Since you are using AjaxProxy to load a data, you should also use that AjaxProxy to save.

Please look at the example.
http://examples2.ext.net/#/GridPanel/Saving_Variations/WebService/