[CLOSED] Rebuild accordion with dataviews

  1. #1

    [CLOSED] Rebuild accordion with dataviews

    Hi guys,

    This has been bugging me for days.
    IN the example, click on one of the two populate buttons and the accordion is generated perfectly. Close the window and click on the other button and it crashes. Not including the dataview causes everything to work.

    There must be something that can clean the accordion and rebuild it in just one round trip.

    <%@ Page Language="C#" %>
     
    <script runat="server">
    
        public class Section
        {
            public int SectionId { get; set;}
            public string Name { get; set;}
        }
            
        public class Photo
        {
            public int Id { get; set;}
            public int SectionId { get; set;}
            public string ThumbUrl { get; set;}
        }
            
        protected void Populate1(object sender, DirectEventArgs e)
        {
            populate(1, 10);
        }
    
        protected void Populate2(object sender, DirectEventArgs e)
        {
            populate(3, 8);
        }
        
        
        protected void GetPhotos(object sender, DirectEventArgs e)
        {
            stPhotos.DataSource = getPhotos();
            stPhotos.DataBind();
        }
        
        private void populate(int from, int to)
        {
    
            targetSections.ClearContent();
            
            foreach (var section in getSections(from, to))
            {
                var panel = new Ext.Net.Panel
                {
                    ID = "S" + section.SectionId,
                    Title = section.Name,
                    AutoScroll = true
                };
    
                DataView view = new DataView
                {
                    ID = "V" + section.SectionId,
                    AutoScroll = true,
                    ItemSelector = "div.sourcePhoto",
                    OverItemCls = "x-item-over",
                    SelectedItemCls = "x-item-selected",
                    StoreID = "stPhotos",
                    Tpl = new XTemplate
                    {
                        Html = "<tpl for='.'><div class='sourcePhoto'>{ThumbUrl}</div></tpl>"
                    }
                };
                
                panel.Items.Add(view);
                targetSections.Items.Add(panel);
            }
    
            targetSections.UpdateContent();
    
            wPhotos.Show();
        }
        
        private List<Section> getSections(int from, int to)
        {
            var newList = new List<Section>();
     
            for(int i=from; i <= to; i++)
            {
                newList.Add(new Section { SectionId=i, Name=string.Format("Section {0}",i) } );
            }
            return newList;
        }
    
        private List<Photo> getPhotos()
        {
            var newList = new List<Photo>();
    
            for (int i = 1; i <= 4; i++)
            {
                newList.Add(new Photo { Id=i, SectionId = i, ThumbUrl = string.Format("Thumb{0}.jpg", i) });
            }
            return newList;
        }
    </script>
       
    <!DOCTYPE html>
       
    <html>
    <head id="Head1" runat="server">
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" ScriptMode="Debug" />
       
            <ext:Button ID="Button1" runat="server" Text="Populate 1-10" OnDirectClick="Populate1" />
            <ext:Button ID="Button2" runat="server" Text="Populate 3-8" OnDirectClick="Populate2" />
    
                <ext:Window ID="wPhotos" runat="server"
                    Title="Photos"
                    Hidden="True"
                    Width="890"
                    MinWidth="680"
                    Height="700"
                    MinHeight="620"
                    Layout="BorderLayout"
                    Modal="true">
                    <Loader runat="server" AutoLoad="false">
                        <LoadMask ShowMask="true" Msg="Checking for photos..." />
                    </Loader>
                    <Bin>
                        <ext:Store
                            ID="stPhotos" runat="server">
                            <Model>
                                <ext:Model runat="server" IDProperty="Id">
                                    <Fields>
                                        <ext:ModelField Name="Id" Type="Int" />
                                        <ext:ModelField Name="ThumbUrl" Type="String" />
                                        <ext:ModelField Name="SectionId" Type="Int" />
                                    </Fields>
                                </ext:Model>
                            </Model>
                        </ext:Store>
                    </Bin>
                    <Items>
                        <ext:Panel ID="targetSections" runat="server"
                            AnchorHorizontal="100%"
                            AutoScroll="True"
                            Collapsible="False"
                            Layout="AccordionLayout"
                            MarginSpec="0 0 10 0"
                            Padding="0"
                            Region="East"
                            Width="355">
                        </ext:Panel>
                    </Items>
                    <DirectEvents>
                        <Show OnEvent="GetPhotos" />
                    </DirectEvents>
                </ext:Window>
        </form>
    </body>
    </html>
    Last edited by Daniil; Aug 12, 2014 at 5:58 AM. Reason: [CLOSED]
  2. #2
    Hi @Arbee,

    Please set AutoDestroy="false" for the Store.

    Otherwise it is being destroyed with a DataView.
  3. #3
    Thanks Daniil.
    That sorted it.

Similar Threads

  1. Replies: 0
    Last Post: Apr 24, 2014, 10:25 AM
  2. [CLOSED] Rebuild Row Index of column
    By immenso in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Apr 08, 2014, 2:06 PM
  3. [CLOSED] Paging Toolbars on DataViews
    By Juls in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Feb 27, 2014, 11:48 AM
  4. problem on rebuild in ASP.net 4
    By captainst in forum 1.x Help
    Replies: 1
    Last Post: Oct 10, 2011, 2:47 AM
  5. Replies: 5
    Last Post: Nov 11, 2010, 7:33 PM

Tags for this Thread

Posting Permissions