Grid using Store on ObjectDataSource conflict primary key on save and cannot delete ....

  1. #1

    Grid using Store on ObjectDataSource conflict primary key on save and cannot delete ....

    Greeting, I need some help ...

    This is my code

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SetTahun.aspx.cs" Inherits="WebApplication1.Setup.SetTahun1" %>
    <!DOCTYPE html>
    <html xmlns="">
    <head runat="server">
            function insertRecord(grid) {
                var store =,
                    row = store.indexOf(store.insert(0, {  })[0]);
                Ext.defer(function () {
                    grid.editingPlugin.startEditByPosition({ row: row, column: 0 });
                }, 100);
        <form id="form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" Theme="Classic">
            <ext:Viewport ID="Viewport1" runat="server" Layout="FitLayout">
                    <ext:Panel runat="server" ID="PanelGrid" Region="North" Layout="FitLayout" Border="false">
                            <ext:GridPanel ID="GridPanelTahun" runat="server" Scroll="Both" Border="false" >
                                    <ext:Store ID="StoreTahun" 
                                            <ext:Model runat="server">
                                                    <ext:ModelField Name="IDTAHUN" Type="String" />
                                                    <ext:ModelField Name="TAHUN"  Type="String" />
                                                    <EventMask ShowMask="true" CustomTarget="App.GridPanelTahun.getView().el" />
                                <ColumnModel ID="PrpColMdl" IDMode="Legacy" Enabled="true">
                                        <ext:Column runat="server" ColumnID="IDTAHUN" DataIndex="IDTAHUN" Header="<b>ID Tahun</b>"  Sortable="True" Flex="2" > <%--DataIndex="IDTAHUN"--%>
                                                <ext:TextField ID="e_IDTahun" runat="server" AllowBlank="false" MaxLengthText="2" MaxLength="2" />
                                        <ext:Column runat="server" ColumnID="TAHUN" DataIndex="TAHUN" Header="<b>Tahun</b>"  Sortable="True" Flex="1"> <%--DataIndex="TAHUN"--%>
                                                <ext:TextField ID="e_Tahun" runat="server" AllowBlank="false"  />
                                    <ext:PagingToolBar ID="PagingToolBar1" runat="server" StoreID="StoreTahun" DisplayInfo="True" />
                                    <ext:RowSelectionModel runat="server" Mode="Multi">
                                            <Select Handler="#{btnDelete}.enable();" />
                                            <Deselect Handler="if (!#{GridPanelTahun}.selModel.hasSelection()) {
                                                               }" />
                                    <ext:CellEditing runat="server" />
                            <ext:Button ID="btnInsert" runat="server" Text="Tambah" Icon="Add"> <%--button --Insert-- --%>
                                    <%--<Click Handler="#{GridPanelTahun}.insertRecord(0, 0);
                                                    #{GridPanelTahun}.startEditing(0, 0);" />--%>
                                    <Click Handler="#{StoreTahun}.insert(0, {});#{GridPanelTahun}.editingPlugin.startEditByPosition({row:0, column:0});" />
                            <ext:Button ID="btnDelete" runat="server" Text="Hapus" Icon="Delete"> <%--button --Delete-- --%>
                                    <Click Handler="{title:'Konfirmasi',
                                                    msg: 'Hapus data yang dipilih?',
                                                    buttons: Ext.Msg.YESNO,
                                                    fn: function(response) {
                                                        if ('yes' !== response) {
                                                    icon: Ext.MessageBox.QUESTION});" />
                            <ext:Button ID="btnSave" runat="server" Text="Simpan" Icon="Disk"> <%--button --button Save-- --%>
                                    <Click Handler="#{StoreTahun}.sync();" /><%--<Click Handler="#{GridPanelTahun}.save();" />--%>
                            <ext:Button ID="btnRefresh" runat="server"  AutoPostBack="false" Text="Refresh" Icon="ArrowRefresh"> <%--button --Refresh-- --%>
                                    <Click Handler="#{StoreTahun}.reload();" /> <%--<Click Handler="#{GridPanelTahun}.reload();" />--%>
    after I insert new data then click on 'Simpan' button always show this picture :
    Click image for larger version. 

Name:	aset_1.png 
Views:	32 
Size:	26.5 KB 
ID:	25341

    and when I delete data .... they are delete from grid, but after I refresh it show up again and when I check on database ... they're not deleted
    what's solution for that error .... thank's
    Last edited by fabricio.murta; May 22, 2020 at 1:23 PM. Reason: Wrap code in [code][/code] tags.
  2. #2
    Hello @muhammadantoniussony, and welcome to Ext.NET forums!

    I have edited your message to wrap the code block in [code][/code] tags.

    I see your code sample is not something I can just copypaste and run on my side for various missing resources. I will try to help you pointing examples in Examples Explorer using this concept so you can check whether they cover your use case. Here are the examples:

    - GridPanel > DataSource_Controls > ObjectDataSource
    - GridPanel > Paging_and_Sorting > DirectMethod
    - GridPanel > Paging_and_Sorting > Page

    If that doesn't help, in your code sample, can you stub out the object data source to some mock/static data that reproduces the issue, so that we can reproduce it our side and tell you what you can do to fix the issue? You may just edit your first post to add the proper code so that we can check it.

    If you edit your thread above, also make another post here telling you did so we can check (or else we won't get notified of updates to this thread).

    You can check the examples above to a "shape" of simplified code (code behind+page on the same file, etc), and please also review our guidelines as they contain helpful information:

    - Tips for creating simplified code samples
    - More Information Required
    - Forum Guidelines

    Hope this helps!
  3. #3

    Thank you ...

    Thank you ....
    I've already repair my code on this ID=btnInsert and ID=btnDelete

                            <ext:Button ID="btnInsert" runat="server" Text="Tambah" Icon="Add"> <%--button --Insert-- --%>
                                    <Click Handler="insertRecord(#{GridPanelTahun});" />
                            <ext:Button ID="btnDelete" runat="server" Text="Hapus" Icon="Delete" Disabled="true"> <%--button --Delete-- --%>
                                    <Click Handler="{title:'Konfirmasi',
                                                    msg: 'Hapus data yang dipilih?',
                                                    buttons: Ext.Msg.YESNO,
                                                    fn: function(response) {
    				                                    if ('yes' !== response) {
    					                                    return;} else {
                                                        #{btnDelete}.disable();} },
                                                    icon: Ext.MessageBox.QUESTION});" />
    and for the code behind become :
    protected void StoreTahun_AfterRecordInserted(object sender, AfterRecordInsertedEventArgs e)
        Belant.Asset.DAL.Tahun tah = e.Object<Belant.Asset.DAL.Tahun>();
        e.Keys.Add("IDTAHUN", tah.IDTAHUN.Trim());
    protected void StoreTahun_BeforeRecordInserted(object sender, BeforeRecordInsertedEventArgs e)
        //UserLogin agama = e.Object<UserLogin>();
        Tahun tah = e.Object<Tahun>();
        Tahun ul = new Tahun();
        ThnManager tahm = new ThnManager();
        ul = tahm.GetItembyID(tah.IDTAHUN);
        if (ul != null) {
            e.Cancel = true;
            this.ResourceManager1.AddScript("{title:'Perhatian',msg: 'Field <b>ID Tahun</b> Sudah Ada <br>Data Gagal Disimpan...!',buttons: Ext.Msg.OK,icon: Ext.MessageBox.WARNING});");
            this.ResourceManager1.AddScript("{title:'Informasi',msg: 'Data Berhasil <b>Disimpan</b> dan <b>Di-Update</b>',buttons: Ext.Msg.OK,icon: Ext.MessageBox.INFORMATION});");
    and now it's work fine on insert, save, delete and refresh data on grid panel using objectdatasource and store ....
    Thank's ...
  4. #4
    Hello, @muhammadantoniussony!

    Glad you could find a solution for the issue you faced, and thanks for sharing it. We really appreciate it!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. [CLOSED] Insert, Update, Delete in CalendarPanel using ObjectDataSource
    By asiaesolutions in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Feb 21, 2013, 11:53 AM
  2. Replies: 17
    Last Post: Sep 27, 2012, 3:18 PM
  3. [CLOSED] Store and 3 Primary Key
    By pdcase in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Nov 23, 2010, 11:21 AM
  4. [CLOSED] Gridview Primary Key
    By GmServizi in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Aug 08, 2009, 10:08 AM
  5. Replies: 4
    Last Post: Oct 24, 2008, 12:31 PM

Posting Permissions