[CLOSED] dynamically binding a control's store to new dataset

  1. #1

    [CLOSED] dynamically binding a control's store to new dataset

    Hi Ext.net,

    Having trouble getting my multiselect combo to reflect any new data dynamically bound to a control (e.g. multicombo).
    I've abstracted the issue out to this simple example below and included some inline comments that specify the problems.
    Any ideas on what I'm missing? This should be trivial, so must be something obvious. Thanks.

    <%@ Page Language="C#" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>MultiCombo - Ext.NET Examples</title>    
    
    <script runat="server">
        private object TestData1
        {
            get
            {
                return new object[]
                {
                    new object[] { "1A", "AVal1" },
                    new object[] { "1B", "AVal2" },
                    new object[] { "1C", "AVal3" },
                    new object[] { "1D", "AVal4" },
                    new object[] { "1E", "AVal5" },
                    new object[] { "1F", "AVal6" }
                };
            }
        }
    
        private object TestData2
        {
            get
            {
                return new object[]
                {
                    new object[] { "2A", "BVal1" },
                    new object[] { "2B", "BVal2" },
                    new object[] { "2C", "BVal3" },
                    new object[] { "2D", "BVal4" },
                    new object[] { "2E", "BVal5" },
                    new object[] { "2F", "BVal6" }
                };
            }
        }
    
        protected override void OnLoad(EventArgs e)
        {
            this.TestCombo.GetStore().DataSource = TestData1;
            this.TestCombo.GetStore().DataBind();
            //during OnLoad of Page's lifecycle, am able to get the comboboxes to reflect whatever dataset I bind against its store's datasource
    
            this.explicitStore.DataSource = TestData1;
            this.explicitStore.DataBind();
    
        }
    
        //should work b/c any call backs to non-static serverside methods should cause the Page lifecycle to execute and allow access to all page's web controls
        [DirectMethod]
        public void DM_RefreshMultiCombo()
        {
            this.TestCombo.GetStore().DataSource = TestData2;
            this.TestCombo.GetStore().DataBind();
            
    
            this.explicitStore.DataSource = TestData2;
            this.explicitStore.DataBind();
    
            //unfortunately DirectMethod unable to get the multi combos to reflect 2nd dataset
        }
    
        //should also work b/c any call backs to non-static serverside methods should cause the Page lifecycle to execute and allow access to all page's web controls
        protected void DE_RefreshMultiCombo(object sender, DirectEventArgs e)
        {
            this.TestCombo.GetStore().DataSource = TestData2;
            this.TestCombo.GetStore().DataBind();        
    
            this.explicitStore.DataSource = TestData2;
            this.explicitStore.DataBind();
    
            //DirectEvent handler also unable to get the multi combos to reflect 2nd dataset
        }
    </script>
        
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />        
    
            <ext:MultiCombo runat="server" ID="TestCombo" SelectionMode="Selection" DisplayField="name" ValueField="abbr">
                 <Store>
                        <ext:Store runat="server">
                            <Model>
                                <ext:Model runat="server">
                                    <Fields>
                                        <ext:ModelField Name="abbr" />
                                        <ext:ModelField Name="name" />                                    
                                    </Fields>
                                </ext:Model>
                            </Model>
    
                            <Reader>
                                <ext:ArrayReader />
                            </Reader>
                        </ext:Store>
                    </Store>                        
            </ext:MultiCombo>
            <br />
            
            <ext:MultiCombo runat="server" ID="ExplicitStoreCombo" SelectionMode="Selection" DisplayField="name" ValueField="abbr">
                 <Store>
                        <ext:Store ID="explicitStore" runat="server">
                            <Model>
                                <ext:Model runat="server">
                                    <Fields>
                                        <ext:ModelField Name="abbr" />
                                        <ext:ModelField Name="name" />                                    
                                    </Fields>
                                </ext:Model>
                            </Model>
    
                            <Reader>
                                <ext:ArrayReader />
                            </Reader>
                        </ext:Store>
                    </Store>                        
            </ext:MultiCombo>
            <br />
    
            <ext:Button
                ID="Button1"
                runat="server"            
                Text="Load MultiCombo w/ DirectMethod"
                >
                <Listeners>
                    <Click Handler="App.direct.DM_RefreshMultiCombo();" />
                </Listeners>            
            </ext:Button>
    
            <ext:Button
                ID="Button2"
                runat="server"            
                Text="Load MultiCombo w/ DirectEvent"            
                >
                <DirectEvents>
                    <Click OnEvent="DE_RefreshMultiCombo" />
                </DirectEvents>
            </ext:Button>
        </form>
    </body>
    </html>
    Last edited by fabricio.murta; Oct 25, 2018 at 9:39 PM.
  2. #2
    Hi Ext.NET, just following up on some help for this.
    Hopefully this is something trivial?
  3. #3
    Hello @Caleb!

    Sorry for the delay, for some reason the post notification didn't make it to us. We're looking up your inquiry and will post a follow-up as soon as we have an answer!
    Fabrício Murta
    Developer & Support Expert
  4. #4
    And, hello again @Caleb!

    The issue becomes trivial only when you check what data is being returned in the example you provided, if you look with the browser's developer tools network monitor.

    If you look at it, you'll see the data that comes back every direct method/event is but TestData1! This just means that just OnLoad() is being called -- in fact it is called every remote/AJAX call is made to the page, and that's how it should work (if you consider Asp.NET pages' life cycle).

    So, just hinder the OnLoad() event from binding the data if the call was due to an AJAX or postback request and you should be good.

    protected override void OnLoad(EventArgs e)
    {
        if (!X.IsAjaxRequest && !IsPostBack)
        {
            //this.TestCombo.Data = TestData1;
            //this.TestCombo.DataBind();
            this.TestCombo.GetStore().DataSource = TestData1;
            this.TestCombo.GetStore().DataBind();
            //during OnLoad of Page's lifecycle, am able to get the comboboxes to reflect whatever dataset I bind against its store's datasource
    
            this.explicitStore.DataSource = TestData1;
            this.explicitStore.DataBind();
        }
    }
    Hope this helps! And sorry again for not seeing to the post earlier, thanks for sending the follow up to remind us of the thread!
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Thanks fabricio! i forgot to guard my page load w/ a check for AJAX postback and/or standard ASP.NET webform postback. So yea, that was the thing that was messing this trivial example up. Please help me close this thread, and help me with a new thread I'm just about to post.

    This was just a simple thing that I needed to ask a more important question about how the comboboxes selectall() method works. It seems to me that maybe that method, or the comboboxes selecteditems property is not acting the way i'd expect.
  6. #6
    Yes, that's usually a thing we do on Page_Load() but could easily forget if the event handler is another (like OnLoad()).

    This is actually more common to use Page_Load(). I'm not sure how seriously it could threat the code loading execution, but if not Page_Load(), you'd better also call the base event when overriding OnLoad() or other events. Or just be aware something else may break because of the event override.

    I have responded your inquiry on the thread you created under ComboBox's SelectAll() method or its SelectedItems property seems out of synch.

    Thanks for taking your time in opening the thread and providing the test case, it really helps us understand your issue and be able to help you in return!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. [CLOSED] Convert Dataset to Store
    By mapperez in forum 2.x Premium Help
    Replies: 1
    Last Post: May 21, 2014, 6:29 AM
  2. Replies: 2
    Last Post: Sep 27, 2011, 8:25 AM
  3. Replies: 7
    Last Post: Jun 03, 2011, 10:18 PM
  4. [CLOSED] store to dataset
    By speedstepmem4 in forum 1.x Premium Help
    Replies: 7
    Last Post: Apr 29, 2009, 10:48 AM
  5. Replies: 2
    Last Post: Oct 20, 2008, 12:48 AM

Posting Permissions