[CLOSED] Store not populated/updated if I do a clear/empty data just before filling the data

  1. #1

    [CLOSED] Store not populated/updated if I do a clear/empty data just before filling the data

    Hey again!

    I have noticed a problem. In moste pages I have data to be filled in forms and Controls. Usually I also create a method to clear all data, ie clear all stores, clear all comboBoxes, TextFields etc etc.

    Normally I want to do a Clear before populating data. This ensures that all fields are empty, and whatever data I populate thereafter will be added to an empty scene so to speak.

    What I discovered was that if I first execute such a Clear-method, and then populate the data, the data will not be populated at all. If I do not execute the Clear first, then the data is populated.

    I dont get why.

    Heres a runnable example:

    
    <%@ Page Language="C#" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <%@ Register TagPrefix="CP" TagName="MyUserControl" Src="MyUserControl.ascx" %>
    
    <script runat="server">
        
    </script>
           
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
       
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Ext.NET Examples</title>
        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!X.IsAjaxRequest)
                {
                    List<object> data = new List<object>();
                    data.Add(new object[] { "bla1", "bla2", "bla3" });
                    Store1.DataSource = data;
                    Store1.DataBind();
                }
            }
    
            public void ClearData()
            {
                List<object> data = new List<object>();
                Store1.DataSource = data;
                Store1.DataBind();
            }
            
            [DirectMethod]
            public void FillData()
            {
                ClearData(); // If this is not commented out, then NewDataX will not be populated. If I comment this out, it works
    
                List<object> data = new List<object>();
                data.Add(new object[] { "NewData1", "NewData2", "NewData3" });
                Store1.DataSource = data;
                Store1.DataBind();
            }
        
        </script>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
                  
             <ext:Button runat="server" ID="btnTest" Text="test">
                <Listeners>
                    <Click Handler="Ext.net.DirectMethods.FillData();" />
                </Listeners>
             </ext:Button>
             <ext:GridPanel ID="GridPanel2" runat="server" StripeRows="true" Header="true" Border="true" Layout="Fit" AutoHeight="true">
                <Store>
                    <ext:Store runat="server" ID="Store1" AutoLoad="true">
                        <Reader>
                            <ext:ArrayReader>
                                <Fields>
                                    <ext:RecordField Name="Data1"></ext:RecordField>
                                    <ext:RecordField Name="Data2"></ext:RecordField>
                                    <ext:RecordField Name="Data3"></ext:RecordField>
                                </Fields>
                            </ext:ArrayReader>
                        </Reader>
                    </ext:Store>
                </Store>
                <ColumnModel ID="ColumnModel2" runat="server" >
                    <Columns>
                        <ext:Column DataIndex="Data1" Header="d1" />
                        <ext:Column DataIndex="Data2" Header="d2" />
                        <ext:Column DataIndex="Data3" Header="d3"  />
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>
        </form>
    </body>
    </html>
    Last edited by geoffrey.mcgill; May 18, 2011 at 6:46 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Store cannot be binded two times per request.
    What a sense in the clearing? When you bind new data then previous data will be destroyed automatically
  3. #3
    Vladimir, thanks for the answer - that explains it.

    In the above example it has of course no point. But I have other, real world situations, where there are a lot of fields and data around. Its not all the time that all the data is updated (because of lack of data etc).

    For me it has been an easy thing to have one clear method where I simply store everything that should be cleared on the page/form. Then I populate the fields that I want, without thinking of what fields/STores I am not updating right now.

    If I forget to update something, the data will linger and that is no good.

    But given the answer you provided, I have no choice in the matter.
  4. #4
    Hi,

    You can try to call RemoveAll method for the store in the ClearData method
  5. #5
    Thanks! That was a lot better! I can perhaps use that instead in my real project =)

    Whats the technical difference between doing a dataBind and a RemoveAll?
  6. #6
    Quote Originally Posted by wagger View Post
    Whats the technical difference between doing a dataBind and a RemoveAll?
    I guess you mean ClearData and RemoveAll?

Similar Threads

  1. Replies: 4
    Last Post: Jul 08, 2011, 4:23 PM
  2. How Gridview in a Gridpanel is populated by data?
    By masudcseku in forum 1.x Help
    Replies: 1
    Last Post: Dec 08, 2010, 1:16 AM
  3. [CLOSED] How to Get Updated .data.items.length from Store (v8.2)
    By iansriley in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 02, 2010, 8:33 PM
  4. Data updated in store with e.record.set() is not getting reflected in grid
    By n_s_adhikari@rediffmail.com in forum 1.x Help
    Replies: 2
    Last Post: May 07, 2010, 5:16 AM
  5. Replies: 4
    Last Post: Nov 17, 2008, 8:16 AM

Tags for this Thread

Posting Permissions