Gridpanel update/delete failing

  1. #1

    Gridpanel update/delete failing

    I am trying to use the gridpanel example in my application and have changed table/column names in my page according to my db. Insert is working fine, but I am getting errors on update/delete

    Commit failed : Reason: Some records have no success confirmation!

    I suspect some problem with parameter definition, but i m not sure, I am using following code

        <form id="form1" runat="server">
        <ext:ResourceManager runat="server">
        </ext:ResourceManager>
    
     <asp:SqlDataSource 
                ID="SqlDataSource1" 
                runat="server" 
                ConnectionString="<%$ ConnectionStrings:constring %>"
                DeleteCommand="DELETE FROM Module_Mst WHERE (id = @id)"
                InsertCommand="INSERT INTO module_mst 
                                   (module_name, module_folder, module_active, display_sort) 
                                VALUES 
                                    (@module_name, @module_folder, case when @module_active = 'True' then '1' else '0' end, @display_sort);                         
                                SELECT @newId = @@Identity;"
                                
                SelectCommand="SELECT 
                                    module_name, module_folder, module_active, display_sort from module_mst order by display_sort"
                               
                UpdateCommand="UPDATE module_mst SET 
                                    module_name = @module_name, 
                                    module_folder = @module_folder, 
                                    module_active = case when @module_active = 'true' then '1' else '0' end, 
                                    display_sort = @display_sort WHERE (id = @id)"
                               
                OnInserted="SqlDataSource1_Inserted">
                
                <DeleteParameters>
                    <asp:Parameter Name="id" Type="Int32" />
                </DeleteParameters>
                
                <UpdateParameters>
                    <asp:Parameter Name="module_name" Type="String" />
                    <asp:Parameter Name="module_folder" Type="String" />
                    <asp:Parameter Name="module_active" Type="String" />
                    <asp:Parameter Name="display_sort" Type="Int16" />
                    <asp:Parameter Name="id" Type="Int32" />
                </UpdateParameters>
                
                <InsertParameters>
                    <asp:Parameter Name="module_name" Type="String" />
                    <asp:Parameter Name="module_folder" Type="String" />
                    <asp:Parameter Name="module_active" Type="String" />
                    <asp:Parameter Name="display_sort" Type="Int16" />
                    <asp:Parameter Direction="Output" Name="newId" Type="Int32" />
                </InsertParameters>
            </asp:SqlDataSource>
            
            <ext:Store 
                ID="Store1" 
                runat="server" 
                DataSourceID="SqlDataSource1" 
                ShowWarningOnFailure="true"
                OnAfterDirectEvent="Store1_AfterDirectEvent"
                OnBeforeDirectEvent="Store1_BeforeDirectEvent" 
                UseIdConfirmation="true" 
                OnBeforeRecordInserted="Store1_BeforeRecordInserted"
                OnAfterRecordInserted="Store1_AfterRecordInserted"
                OnRefreshData="Store1_RefershData">
                <Reader>
                    <ext:JsonReader IDProperty="id">
                        <Fields>
                            <ext:RecordField Name="module_name" />
                            <ext:RecordField Name="module_folder" />
                            <ext:RecordField Name="module_active" />
                            <ext:RecordField Name="display_sort" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
                <SortInfo Field="display_sort" Direction="ASC" />
                <Listeners>
                    <LoadException Handler="Ext.Msg.alert('Module master - Load failed', e.message || e);" />
                    <CommitFailed Handler="Ext.Msg.alert('Module master - Commit failed', 'Reason: ' + msg);" />
                    <SaveException Handler="Ext.Msg.alert('Module master - Save failed', e.message || e);" />
                    <CommitDone Handler="Ext.Msg.alert('Module master - Commit', 'The data successfully saved');" />
                </Listeners>      
            </ext:Store>
            
            <ext:Viewport ID="Viewport1" runat="server">
                <Items>
                    <ext:BorderLayout ID="BorderLayout1" runat="server">
                        <Center MarginsSummary="0 5 0 5">
                            <ext:Panel ID="Panel2" runat="server" Height="300" Header="false" Layout="Fit">
                                <Items>
                                    <ext:GridPanel 
                                        ID="GridPanel1" 
                                        runat="server"  
                                        Title="Module master" 
                                        AutoExpandColumn="module_name"
                                        StoreID="Store1" 
                                        Border="false" 
                                        Icon="Lorry">
                                        <ColumnModel ID="ColumnModel1" runat="server">
                                            <Columns>
                                                <ext:Column 
                                                    ColumnID="module_name" 
                                                    DataIndex="module_name" 
                                                    Header="Module Name">
                                                    <Editor>
                                                        <ext:TextField ID="TextField1" runat="server" />
                                                    </Editor>
                                                </ext:Column>
                                                <ext:Column DataIndex="module_folder" Header="Module folder">
                                                    <Editor>
                                                        <ext:TextField ID="TextField2" runat="server" />
                                                    </Editor>
                                                </ext:Column>
                                                <ext:Column DataIndex="module_active" Header="Is Active">
                                                    <Editor>
                                                        <ext:Checkbox ID="chkActive" runat="server"></ext:Checkbox>
                                                    </Editor>
                                                </ext:Column>
                                                <ext:Column DataIndex="display_sort" Header="Tab order">
                                                    <Editor>
                                                    <ext:SpinnerField ID="spnSort" runat="server"></ext:SpinnerField>
                                                    </Editor>
                                                </ext:Column>
                                            </Columns>
                                        </ColumnModel>                                    
                                        <SelectionModel>
                                            <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />
                                        </SelectionModel>
                                        <BottomBar>
                                            <ext:PagingToolbar ID="PagingToolbar1" 
                                                runat="server" 
                                                PageSize="10" 
                                                StoreID="Store1" 
                                                DisplayInfo="false" 
                                                />
                                        </BottomBar>
                                        <SaveMask ShowMask="true" />
                                        <LoadMask ShowMask="true" />
                                    </ext:GridPanel>
                                </Items>
                                <Buttons>
                                    <ext:Button ID="btnSave" runat="server"  Text="Save" Icon="Disk">
                                        <Listeners>
                                            <Click Handler="#{GridPanel1}.save();" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:Button ID="btnDelete" runat="server"  Text="Delete selected records" Icon="Delete">
                                        <Listeners>
                                            <Click Handler="#{GridPanel1}.deleteSelected();" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:Button ID="btnInsert" runat="server"  Text="Insert" Icon="Add">
                                        <Listeners>
                                            <Click Handler="#{GridPanel1}.insertRecord(0, {});#{GridPanel1}.getView().focusRow(0);#{GridPanel1}.startEditing(0, 0);" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:Button ID="btnRefresh" runat="server"  Text="Refresh" Icon="ArrowRefresh">
                                        <Listeners>
                                            <Click Handler="#{GridPanel1}.reload();" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:Button ID="btnEmulError" runat="server"  Text="Refresh with Emulated error" Icon="Exclamation">
                                        <Listeners>
                                            <Click Handler="#{GridPanel1}.reload({params:{EmulateError: 1}});" />
                                        </Listeners>
                                    </ext:Button>                           
                                </Buttons>
                            </ext:Panel>
                        </Center>             
                    </ext:BorderLayout>
                </Items>
            </ext:Viewport>
        </form>
    and in the backend
    using Ext.Net;
    public partial class Admin_Admin_frmManagemodule : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
    
        private bool cancel;
        private string message;
        private string insertedValue;
    
        protected void Store1_BeforeRecordInserted(object sender, BeforeRecordInsertedEventArgs e)
        {
            //object region = e.NewValues["Region"];
    
            //if (region == null || region.ToString() != "Alabama (AL)")
            //{
            //    e.Cancel = true;
            //    this.cancel = true;
            //    this.message = "The Region must be 'AL'";
            //}
        }
    
        protected void Store1_AfterRecordInserted(object sender, AfterRecordInsertedEventArgs e)
        {
            //The deleted and updated records confirms automatic (depending AffectedRows field)
            //But you can override this in AfterRecordUpdated and AfterRecordDeleted event
            //For insert we should set new id for refresh on client
            //If we don't set new id then old id will be used
            if (e.Confirmation.Confirm && !string.IsNullOrEmpty(insertedValue))
            {
                e.Confirmation.ConfirmRecord(insertedValue);
                insertedValue = "";
            }
        }
    
        protected void SqlDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e)
        {
            //use e.AffectedRows for ensure success action. The store read this value and set predefined Confirm depend on e.AffectedRows
            //The Confirm can be granted or denied in OnRecord....ed event
            insertedValue = e.Command.Parameters["@newId"].Value != null
                                ? e.Command.Parameters["@newId"].Value.ToString()
                                : "";
        }
    
        protected void Store1_AfterDirectEvent(object sender, AfterDirectEventArgs e)
        {
            if (e.Response.Success)
            {
                // set to .Success to false if we want to return a failure
                e.Response.Success = !cancel;
                e.Response.Message = message;
                //if (this.cancel)
                // {
                // GridPanel1.AddScript("alert({0});", JSON.Serialize(this.message));
                //}
            }
        }
    
        protected void Store1_BeforeDirectEvent(object sender, BeforeDirectEventArgs e)
        {
            string emulError = e.Parameters["EmulateError"];
    
            if (emulError == "1")
            {
                throw new Exception("Emulating error");
            }
        }
    
        protected void Store1_RefershData(object sender, StoreRefreshDataEventArgs e)
        {
            this.Store1.DataBind();
        }
    }

    Thanks
    Last edited by rajesh.chd; Dec 04, 2010 at 11:12 AM.
  2. #2
    Hi,

    I'm not sure where the problem is.

    Hope, this will help:
    http://forums.ext.net/showthread.php...ng-description
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi,

    I'm not sure where the problem is.

    Hope, this will help:
    http://forums.ext.net/showthread.php...ng-description
    Well, while debugging isupdating event of the sqldatasource, I found that @id field is getting negative value. For example if id value is 14, @id field is having -14. I am not sure what the reason is, but if I hardcode update parameter like id = 14 instead of id= @id, then data is being updated.
  4. #4
    Hi,

    One problem I see with the JsonReader's IDProperty. There must be RecordField with "id" Name.

    Wrong
    <ext:JsonReader IDProperty="id">
        <Fields>
            <ext:RecordField Name="module_name" />
            <ext:RecordField Name="module_folder" />
            <ext:RecordField Name="module_active" />
            <ext:RecordField Name="display_sort" />
        </Fields>
    </ext:JsonReader>
    Right
    <ext:JsonReader IDProperty="id">
        <Fields>
            <ext:RecordField Name="module_name" />
            <ext:RecordField Name="module_folder" />
            <ext:RecordField Name="module_active" />
            <ext:RecordField Name="display_sort" />
            <ext:RecordField Name="id" />
        </Fields>
    </ext:JsonReader>
    But I'm not sure this causes the issue.

    See also
    http://dev.sencha.com/deploy/dev/doc...ber=idProperty
    Last edited by Daniil; Dec 07, 2010 at 11:08 AM. Reason: Minor correction
  5. #5
    @Danill

    Thanks for your replies. Though that was not the cause of the problem. But I appreciate your help.

    Sometimes we miss small details, and that was the cause here. What was happening is that I was not selecting "id" in the select query, and gridpanel was assuming row number as id, and due to some reason unknown to me showing it in negative which was causing confusion.

    Thanks for nice controls, now I have got it worked, I have started playing with it and liking it.
  6. #6
    Quote Originally Posted by rajesh.chd View Post
    @Danill

    Thanks for your replies. Though that was not the cause of the problem. But I appreciate your help.

    Sometimes we miss small details, and that was the cause here. What was happening is that I was not selecting "id" in the select query, and gridpanel was assuming row number as id, and due to some reason unknown to me showing it in negative which was causing confusion.

    Thanks for nice controls, now I have got it worked, I have started playing with it and liking it.
    Are you sure this was not the problem?:) I investigate this further and now I'm sure this was the problem.

    http://dev.sencha.com/deploy/dev/doc...&member=Record
    http://dev.sencha.com/deploy/dev/doc...mber=Record.id
  7. #7
    Yes, I am 100% sure about that, because I tested it with

    <ext:JsonReader IDProperty="id">
                    <Fields>
                        <ext:RecordField Name="module_name" />
                        <ext:RecordField Name="module_folder" />
                        <ext:RecordField Name="module_active" />
                        <ext:RecordField Name="display_sort" />
                    </Fields>
     </ext:JsonReader>
    and

    <ext:JsonReader IDProperty="id">
                    <Fields>
                        <ext:RecordField Name="module_name" />
                        <ext:RecordField Name="module_folder" />
                        <ext:RecordField Name="module_active" />
                        <ext:RecordField Name="display_sort" />
                        <ext:RecordField Name="id" />
                    </Fields>
     </ext:JsonReader>
    and it is working perfect with both editions.
  8. #8
    this worked for me

    wrong query
    ---------------
     SelectCommand="SELECT module_name, module_folder, module_active, display_sort from module_mst order by display_sort"
    in this case rownum was assumed as "id" and a negative value was being assigned to it. e.g. rownum 5 would become -5 and 6 would become -6.


    correct query
    ---------------
     SelectCommand="SELECT id, module_name, module_folder, module_active, display_sort from module_mst order by display_sort"
  9. #9
    Ok, thank you for the clarification and sharing the solution. This can help another members.

Similar Threads

  1. Replies: 12
    Last Post: Aug 09, 2013, 2:25 PM
  2. Replies: 1
    Last Post: Mar 26, 2012, 8:59 PM
  3. Replies: 0
    Last Post: Sep 02, 2010, 3:58 AM
  4. Replies: 0
    Last Post: Jul 23, 2010, 6:35 AM
  5. Replies: 0
    Last Post: Jun 10, 2010, 1:18 AM

Tags for this Thread

Posting Permissions