[CLOSED] GridPanel update problems with ObjectDataSource

  1. #1

    [CLOSED] GridPanel update problems with ObjectDataSource



    Hi,

    I need to use a GridPanel control with an ASP.NET ObjectDataSource.

    I start by defining the ObjectDataSource:

    <asp:ObjectDataSource ID="objDSGroups" runat="server" DataObjectTypeName="WindowsGroup" TypeName="WindowsGroups" DeleteMethod="Delete" SelectMethod="Select" UpdateMethod="Update">
    <DeleteParameters>
        <asp:Parameter Name="GroupName" Type="String" />
    </DeleteParameters>
    I define the Store:

    <ext:Store ID="storeGroups" runat="server" OnBeforeRecordDeleted="BeforeGroupRecordDeleted" OnBeforeRecordUpdated="BeforeGroupRecordUpdated" DataSourceID="objectDataSourceGroups" RefreshAfterSaving="None" AutoLoad="True">
        <Reader>
            <ext:JsonReader ReaderID="GroupName">
                <Fields>
                    <ext:RecordField Name="GroupName" Type="String" />
                    <ext:RecordField Name="IsAdmin" Type="String" />
                    <ext:RecordField Name="IsAuthor" Type="String" />
                    <ext:RecordField Name="IsLearner" Type="String" />
                </Fields>
            </ext:JsonReader>
        </Reader>
        <Listeners>
            <CommitDone Handler="#{btnSave}.disable();" />
            <Update Handler="#{btnSave}.enable();" />
        </Listeners>
    </ext:Store>
    The GridPanel is hooked up to the Store - I'll omit the code for now.

    Problem #1: The Select method is called automatically and works fine, but the Update and Delete methods are not. As a workaround, I call these methods manually in the BeforeRecordUpdated and BeforeRecordDeleted handlers.

    Problem #2: The BeforeRecordUpdated and BeforeRecordDeleted handlers are called only for the first affected row, not for each affected row.

    Any suggestions?

    Cheers,
    Jason
  2. #2

    RE: [CLOSED] GridPanel update problems with ObjectDataSource

    Hi,

    Can you add the following listeners to the store:
                <CommitFailed Handler="Ext.Msg.alert('Commit failed', 'Reason: ' + msg)" />
                <SaveException Handler="Ext.Msg.alert('Save failed', e.message || e)" />
    Does the any failure message showing if call save function?

    It would be great if you can post example which demonstrates the problem (for example as attachment)


  3. #3

    RE: [CLOSED] GridPanel update problems with ObjectDataSource

    Thanks for the prompt response.

    The CommitFailed and SaveException listeners don't flag anything. I've attached a simplified example (the source class for the ObjectDataSource simply uses a static collection, rather than retrieving and manipulating data).

    Behaviour is as described previously - Update and Delete methods are not called automatically, and the BeforeRecordDeleted and BeforeRecordUpdated events are fired only for the first affected row.

    Thanks,
  4. #4

    RE: [CLOSED] GridPanel update problems with ObjectDataSource

    Hi Jason,

    Thanks for the good example. I investigated your example and found next:

    1. ObjectDataSource notified that WindowGroup class does not contain non-parametric constructor. I added it
         public WindowsGroup()
        {        
        }
    2. When performs delete action the ObjectDataSource notified that it can't find Delete with paramter which has type WindowGroup (your example contains Delete method with string argument). I added it
    
        public static void Delete(WindowsGroup delGroup)
        {
            WindowsGroup existingGroup = myGroups.Find(delegate(WindowsGroup w) { return w.GroupName == delGroup.GroupName; });
            myGroups.Remove(existingGroup);
        }
    Please note that I comment out your BeforeGroupRecordUpdated and BeforeGroupRecordDeleted handlers. After these changes your example works good.

    If you want to perform own logic in before handlers then you need to set Cancel=true. It avoids standart DataSource actions (it canceled performing standart action only current record, the other records will be handling any way).

    protected void BeforeGroupRecordDeleted(object sender, BeforeRecordDeletedEventArgs e)
            {
                String groupName = e.Keys["GroupName"].ToString();
                WindowsGroups.Delete(groupName);
    
                e.Cancel = true;
            }

  5. #5

    RE: [CLOSED] GridPanel update problems with ObjectDataSource

    Fantastic - problem solved. Thanks for your help.
  6. #6

    Example code

    Hi Vladimir!

    Could you show me the example code of updating database by using object datasource that jason has.I also get same trouble when updating my database by using object data source.

    Thanks.
    Last edited by hondacivic; Nov 17, 2011 at 10:47 PM.

Similar Threads

  1. Store update ObjectDataSource params mismatch
    By Neil_Walters in forum 1.x Help
    Replies: 2
    Last Post: Mar 14, 2010, 10:11 PM
  2. Replies: 1
    Last Post: Jun 11, 2009, 3:59 AM
  3. Problems with asp:ObjectDataSource
    By jpbelli in forum 1.x Help
    Replies: 5
    Last Post: Feb 02, 2009, 1:34 PM
  4. [CLOSED] Problems with asp:ObjectDataSource
    By antonyn in forum 1.x Legacy Premium Help
    Replies: 0
    Last Post: Feb 02, 2009, 10:50 AM
  5. [CLOSED] having trouble understanding ObjectDataSource Update
    By pkellner in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Oct 16, 2008, 3:42 PM

Posting Permissions