[CLOSED] Dynamcally created Combox and its Dynamic Store

  1. #1

    [CLOSED] Dynamcally created Combox and its Dynamic Store

    Hi, I have the following code to dynamically create a combobox with dynamic store. But getting error as "The Control 'Parameter' could not find the StoreID of 'Store1'." How should i modify this code to make it work? Thanks :)
    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">     
        public class Vani { 
            public Vani(string a, string b) 
            { 
              this.VALUE = a; 
              this.VALUE2 = b; 
            } 
        public string VALUE 
        { get; set; } 
     
        public string VALUE2 
           { get; set; } 
     
        }          
        protected void Page_Load(object sender, EventArgs e) 
        { 
            FormLayout schemaFL = new FormLayout();
            schemaFL.ID = "FormPanel1";
            Anchor a = new Anchor(); 
            a.Horizontal = "95%"; 
            JsonReader ar = new JsonReader(); 
            RecordField rf = new RecordField("VALUE", RecordFieldType.String); 
            RecordField rf2 = new RecordField("VALUE2", RecordFieldType.String); 
            ar.Fields.Add(rf); 
            ar.Fields.Add(rf2); 
            Store myStore = new Store(); 
            myStore.ID = "Store1";
            myStore.Reader.Add(ar); 
            myStore.DataSource = new List<Vani> { new Vani("1", "1"), new Vani("2", "2") }; 
            this.form1.Controls.AddAt(0, myStore); 
            myStore.DataBind();
            schemaFL.Anchors.Add(a);
            Panel1.Items.Add(schemaFL); 
     
            new Ext.Net.ComboBox()
            {
                ID = "Parameter",
                FieldLabel = "Test",
                AnchorHorizontal = "95%",
                StoreID = "Store1",
                ValueField = "VALUE",
                DisplayField = "VALUE",
            }.Render("FormPanel1", RenderMode.AddTo);
         //   parametersID = (i == 0 ? "Parameter" + i : parametersID + "^" + "Parameter" + i);
           // a.Items.Add(grid); 
     
            } 
            </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ScriptManager1" runat="server"/>
     
        <ext:Panel runat="server" ID="Panel1" Width="504" Height="450" Title="DOCUMENT" Icon="BookAddresses">
        </ext:Panel>
        </form>
    </body>
    </html>
    Last edited by Daniil; Jan 26, 2011 at 8:24 AM. Reason: [CLOSED]
  2. #2
    Hi,

    Please do not use .Render() method in Page_Load (and similar). Use this method during DirectEvent/Direct only.

    Also don't use Anchor with 'form' layout in Ext.Net 1.0. Just set Layout="form" (also I guess you could just use FormPanel instead of Panel).

    Example
    <%@ Page Language="C#" %>
    
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">    
        public class Vani
        {
            public Vani(string a, string b)
            {
                this.VALUE = a;
                this.VALUE2 = b;
            }
            public string VALUE
            { get; set; }
    
            public string VALUE2
            { get; set; }
    
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                JsonReader ar = new JsonReader();
                RecordField rf = new RecordField("VALUE", RecordFieldType.String);
                RecordField rf2 = new RecordField("VALUE2", RecordFieldType.String);
                ar.Fields.Add(rf);
                ar.Fields.Add(rf2);
    
                Store myStore = new Store();
                myStore.ID = "Store1";
                myStore.Reader.Add(ar);
                myStore.DataSource = new List<Vani> { new Vani("1", "1"), new Vani("2", "2") };
                this.Form.Controls.AddAt(0, myStore);
                myStore.DataBind();
            }
            this.Panel1.Items.Add(new Ext.Net.ComboBox()
            {
                ID = "Parameter",
                FieldLabel = "Test",
                AnchorHorizontal = "95%",
                StoreID = "Store1",
                ValueField = "VALUE",
                DisplayField = "VALUE",
            });
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net Example</title>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:Panel 
            ID="Panel1" 
            runat="server" 
            Width="500" 
            Height="400" 
            Title="DOCUMENT" 
            Icon="BookAddresses" 
            Layout="form" />
        </form>
    </body>
    </html>
    See also
    https://examples1.ext.net/#/Layout/A...hor_With_Form/
    https://examples1.ext.net/#/Layout/FormLayout/Overview/
  3. #3
    Actually the requirement is to generate from the directevent. I recreated the test code. the scenrio is i have a window, then i need to dynamically create a formpanel, then combox with store. please advise how to modify current code. thank you.
    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">     
        public class Vani { 
            public Vani(string a, string b) 
            { 
              this.VALUE = a; 
              this.VALUE2 = b; 
            } 
        public string VALUE 
        { get; set; } 
     
        public string VALUE2 
           { get; set; } 
     
        }
        protected void Generate(object sender, DirectEventArgs e)
        {
     
     
            JsonReader ar = new JsonReader();
            RecordField rf = new RecordField("VALUE", RecordFieldType.String);
            RecordField rf2 = new RecordField("VALUE2", RecordFieldType.String);
            ar.Fields.Add(rf);
            ar.Fields.Add(rf2);
            Store myStore = new Store();
            myStore.ID = "Store1";
            myStore.Reader.Add(ar);
            myStore.DataSource = new List<Vani> { new Vani("1", "1"), new Vani("2", "2") };
            this.form1.Controls.AddAt(0, myStore);
            myStore.DataBind();
           // Panel1.Items.Add(schemaFL);
            var f = new FormPanel
            {
                ID = "FormPanel1",
                Padding = 5,
                LabelWidth = 150,
                AutoHeight = true,
                RenderFormElement = false,
            };
            winFilter.Items.Add(f);
            f.Render();
     
            new Ext.Net.ComboBox()
            {
                ID = "Parameter",
                FieldLabel = "Test",
                AnchorHorizontal = "95%",
                StoreID = "Store1",
                ValueField = "VALUE",
                DisplayField = "VALUE",
            }.Render("FormPanel1", RenderMode.AddTo);
            //   parametersID = (i == 0 ? "Parameter" + i : parametersID + "^" + "Parameter" + i);
        }    
        protected void Page_Load(object sender, EventArgs e) 
        { 
     
           // a.Items.Add(grid); 
     
            } 
            </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ScriptManager1" runat="server"/>
        <ext:Window ID="winFilter" runat="server" Title="Report Filter" Icon="Magnifier"
            Closable="false" Width="400" AutoHeight="true" Resizable="false" BodyStyle="background-color:#fff;"
            Hidden="false" AutoShow="false" Modal="true" Layout="Form">
        <Items>
        <ext:Button runat="server" Text="Test">
        <DirectEvents>
        <Click OnEvent="Generate"></Click>
        </DirectEvents>
        </ext:Button>
        </Items>
        </ext:Window>
        </form>
    </body>
    </html>
  4. #4
    Please investigate the following example.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">    
        public class Vani
        {
            public Vani(string a, string b)
            {
                this.VALUE = a;
                this.VALUE2 = b;
            }
            public string VALUE
            { get; set; }
    
            public string VALUE2
            { get; set; }
    
        }
        protected void Generate(object sender, DirectEventArgs e)
        {
            var f = new FormPanel
            {
                ID = "FormPanel1",
                Padding = 5,
                LabelWidth = 150,
                AutoHeight = true,
            };
    
            Ext.Net.ComboBox combo = new Ext.Net.ComboBox()
            {
                ID = "Parameter",
                FieldLabel = "Test",
                AnchorHorizontal = "95%",
                ValueField = "VALUE",
                DisplayField = "VALUE"
            };
            JsonReader ar = new JsonReader();
            RecordField rf = new RecordField("VALUE", RecordFieldType.String);
            RecordField rf2 = new RecordField("VALUE2", RecordFieldType.String);
            ar.Fields.Add(rf);
            ar.Fields.Add(rf2);
            Store myStore = new Store();
            myStore.ID = "Store1";
            myStore.Reader.Add(ar);
            myStore.DataSource = new List<Vani> { new Vani("1", "1"), new Vani("2", "2") };
            myStore.DataBind();
            combo.Store.Add(myStore);
    
            f.Items.Add(combo);
            f.AddTo(this.Window1);
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net Example</title>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:Window 
            ID="Window1" 
            runat="server" 
            Title="Window" 
            Width="400" 
            AutoHeight="true">
            <Items>
                <ext:Button runat="server" Text="Generate" OnDirectClick="Generate" />
            </Items>
        </ext:Window>
        </form>
    </body>
    </html>
  5. #5
    Thanks for the reply. example works well!

Similar Threads

  1. [CLOSED] Dynamic created MenuItems and directEvents
    By cwolcott in forum 2.x Legacy Premium Help
    Replies: 6
    Last Post: Jun 14, 2012, 5:04 PM
  2. Replies: 0
    Last Post: Feb 06, 2012, 1:59 PM
  3. [CLOSED] Dynamic Created HtmlEditor With Ext.util.Format.htmlEncode
    By SouthDeveloper in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 12, 2011, 12:59 PM
  4. [CLOSED] Combox Editor- Dynamic Combo box list Value
    By vali1993 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Aug 22, 2010, 8:02 PM
  5. Replies: 0
    Last Post: May 20, 2010, 7:57 AM

Posting Permissions