[CLOSED] How to create and load store to combobox in codebehind

  1. #1

    [CLOSED] How to create and load store to combobox in codebehind

    Hi,

    I need to create and load the sotre to combobox in codebehind. I need to do that, because i have a dynamical formpanel (FP), where FP can have textfield and/or combobox.

    This FP can have one of both or many of them, so I need to create and load the store (each store have different data) for each combobox.

    So, how I can do that??.

    I do this in my code, but the FP don't show me anything.


     private void Create()
            {
                    System.Data.DataTable theDataTable = getData(query);
                    int cant = int.Parse(theDataTable.Rows.Count.ToString());
                    if (cant > 0)
                    {                    
                        for (int i = 0; i < cantidad; i++)
                        {
                            System.Data.DataRow theDataRow = getRow();
                            string AtribType = theDataRow["type"].ToString();
                           
                            if (AtribType.Equals(COMBOTYPE))
                            {                            
                                Store str = new Store();
                                str.ID = "Store" + i.ToString();
                                str.Fields.Add(theDataTable.Columns[0].ColumnName);
                                str.Fields.Add(theDataTable.Columns[1].ColumnName, ModelFieldType.String);
                                str.DataSource = theDataTable;
                                str.DataBind();
    
                                FormPanelAtributos.Items.Add(new ComboBox { FieldLabel = theDataRow["columnA"].ToString(), EnableKeyEvents = true, MsgTarget = MessageTarget.Side, AllowBlank = true, QueryMode = DataLoadMode.Local, StoreID=str.ID, DisplayField = theDataTable.Columns[1].ColumnName, ValueField = theDataTable.Columns[1].ColumnName, EmptyText = "Select...", Name = theDataRow["columnB"].ToString() });
                            }
                            else
                            {
                                FormPanelAtributos.Items.Add(new TextField { FieldLabel = theDataRow["columnA"].ToString(), EnableKeyEvents = true, MsgTarget = MessageTarget.Side, AllowBlank = true });
                            }
                        }
                        FormPanelControls.Render(WindowCtr, RenderMode.AddTo);
                    }
    }
    Best Regards.

    Thanks a lot.
    Last edited by Daniil; Apr 21, 2015 at 6:48 PM. Reason: [CLOSED]
  2. #2
    Hi @opendat2000,

    Do you run that code on initial page load? If so, please remove:
    FormPanelControls.Render(WindowCtr, RenderMode.AddTo);
    Or during a DirectEvent?

    A runnable test case would help us to help you as soon as possible.
  3. #3
    Daniil,

    thanks for your prompt reply.

    No, the code is run when I click on a row in a gridpanel and show the windows with the combobox and/or the textfield.


    Example:

    1.- Run the app.
    2.- Select a item in a treepanel.
    3.- Show data in a gridpanel of the item selected in 2.
    4.- Click in one of data.
    5.- Show the window with a X quantity of combobox and/or textfield.

    The window in the point 5 have a different quantity for combobox and/or textfield, this is because that the item selected in the tree panel, are different for others.

    Thanks a lot.

    Best Regards.
  4. #4
    1.- Run the app.
    Please clarify - what the app should I run?
  5. #5
    Run the App is just a example of the step of how works.


    thanks a lot.
  6. #6
    Ok. I think I need such an app to go through the steps. Could you, please, provide?
  7. #7
    Hi,

    Here is a example. This example don't use a datatable for the store, and don't use a treepanel and gridpanel.

    I use a first random like a quantity of rows and a second random to get a type of control.


    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TstComboBoxWindowDynamic.aspx.cs" Inherits="Web2.TstComboBoxWindowDynamic" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)//!this.IsPostBack)
            {
                this.Store1.DataSource = new object[]
                {
                    new object[] { "01-01", "3m Co"},
                    new object[] { "02-02", "Alcoa Inc"},
                    new object[] { "03-03", "Altria Group Inc"},
                    new object[] { "04-04", "American Express Company"},
                    new object[] { "05-05", "American International Group, Inc."},
                    new object[] { "06-06", "AT&T Inc."},
                    new object[] { "07-07", "Boeing Co."},
                    new object[] { "08-08", "Caterpillar Inc."},
                    new object[] { "09-09", "Citigroup, Inc."},
                    new object[] { "10-10", "E.I. du Pont de Nemours and Company"},
                    new object[] { "11-11", "Exxon Mobil Corp"},
                    new object[] { "12-12", "General Electric Company"},
                    new object[] { "13-13", "General Motors Corporation"},
                    new object[] { "14-14", "Hewlett-Packard Co."},
                    new object[] { "15-15", "Honeywell Intl Inc"},
                    new object[] { "16-16", "Intel Corporation"},
                    new object[] { "17-17", "International Business Machines"},
                    new object[] { "18-18", "Johnson & Johnson"},
                    new object[] { "1919", "JP Morgan & Chase & Co"},
                    new object[] { "20-20", "McDonald\"s Corporation"},
                    new object[] { "21-21", "Merck & Co., Inc."},
                    new object[] { "22-22", "Microsoft Corporation"},
                    new object[] { "23-23", "Pfizer Inc"},
                    new object[] { "24-24", "The Coca-Cola Company"},
                    new object[] { "25-25", "The Home Depot, Inc."},
                    new object[] { "26-26", "The Procter & Gamble Company"},
                    new object[] { "27-27", "United Technologies Corporation"},
                    new object[] { "28-28", "Verizon Communications"},
                    new object[] { "29-29", "Wal-Mart Stores, Inc."}
                };
                this.Store1.DataBind();
                            
                
            }
        }
    
        [DirectMethod]
        public void OpenWindow()
        {
            Create();
            Window1.Show();
        }
    
        private void Create()
        {
    
            Random r = new Random();
            int cant = r.Next(1, 5);
            if (cant > 0)
            {
                Random x = new Random();
                int AtribType = x.Next(0, 1);
                for (int i = 0; i < cant; i++)
                {
                    if (AtribType == 0)
                    {
                        Store str = new Store();
                        str.ID = "";//<---- I can't give a id name
                        str.Fields.Add("Columna 1");
                        str.Fields.Add("Columna 2");
                        str.DataSource = new object[]
                        {
                            new object[] { "01-01", "3m Co" },
                            new object[] { "02-02", "Alcoa Inc" },
                            new object[] { "03-03", "Altria Group Inc" },
                            new object[] { "04-04", "American Express Company" },
                            new object[] { "05-05", "American International Group, Inc." },
                    
                        };
    
                        FormPanel1.Items.Add(new ComboBox { FieldLabel = "Label " + i, EnableKeyEvents = true, MsgTarget = MessageTarget.Side, AllowBlank = true, QueryMode = DataLoadMode.Local, StoreID = str.ID, DisplayField = "Columna 1", ValueField = "Columna 2", EmptyText = "Select...", Name = "Name " + x });
                        str.DataBind();
                    }
                    else
                    {
                        FormPanel1.Items.Add(new TextField { FieldLabel = "Label " + i, EnableKeyEvents = true, MsgTarget = MessageTarget.Side, AllowBlank = true });
                    }
                }
                FormPanel1.Render(Window1, RenderMode.AddTo);
            }
        }
        
        protected void RowSelectionModel1_OnCellSelect(object sender, DirectEventArgs e)
        {
            /*ComboBox1.GetStore().ClearFilter();
            ComboBox1.Value = e.ExtraParams["id"].ToString();*/
            ComboBox1.Reset();
            X.Js.AddScript(string.Format("delete {0}.lastQuery;", ComboBox1.ClientID));
            ComboBox1.Value = e.ExtraParams["id"].ToString();
            Window1.Hide();
        }    
    </script>
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head id="Head1" runat="server">
       <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
       <title></title>
    
        <style type="text/css">
            .my-toolbar1
            {
                background-color : #f5f5f5;
                background-image : none;
            }    
            .my-toolbar2
            {
                background-color : #dfeaf2;
                background-image : none;
            }  
        </style>
    </head>
    
        <body>
            <form id="Form1" runat="server">
                <ext:ResourceManager ID="ResourceManager1" runat="server" IDMode="Explicit" Theme="Neptune" />
    
                <ext:Viewport ID="Viewport1" runat="server" Layout="BorderLayout" DefaultAnchor="90%">
                    <Items>
                        <ext:Panel ID="Panel1" runat="server" 
                                Region="North"
                                Margins="5 5 5 5"
                                BodyPadding="5"
                                Frame="true" >
                            <DockedItems>
                                <ext:Toolbar ID="Toolbar2" runat="server" Dock="Top" Cls="my-toolbar2">
                                    <Items>
                                        <ext:FieldContainer ID="FieldContainer1" runat="server" Layout="HBoxLayout" FieldLabel="Company" AnchorHorizontal="100%">
                                            <Items>
                                                <ext:ComboBox ID="ComboBox1" runat="server"
                                                        AllowBlank="true"
                                                        DisplayField="company"
                                                        ValueField="id"
                                                        QueryMode="Local"
                                                        TypeAhead="true"
                                                        ForceSelection="true"
                                                        TriggerAction="All"
                                                        Name="id_company" Width="380"
                                                        EmptyText="Select Company">
                                                    <Store>
                                                        <ext:Store ID="Store1" runat="server" >               
                                                            <Model>
                                                                <ext:Model ID="Model1" runat="server">
                                                                    <Fields>
                                                                        <ext:ModelField Name="id"/>
                                                                        <ext:ModelField Name="company" />
                                                                    </Fields>
                                                                </ext:Model>
                                                            </Model>
                                                        </ext:Store>
                                                    </Store>
                                                    <Triggers>
                                                        <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                                                    </Triggers>
                                                    <DirectEvents>
                                                        <Select>
                                                            <EventMask ShowMask="true" />
                                                        </Select>
                                                    </DirectEvents>
                                                    <ListConfig>
                                                        <ItemTpl ID="ItemTpl2" runat="server">
                                                            <Html>
                                                                <div class="list-item">
    							                                    <h3>{company}</h3>
    							                                        {id}
    						                                    </div>
                                                            </Html>
                                                        </ItemTpl>
                                                    </ListConfig>
                                                    <Listeners>
                                                        <Change Handler="this.getTrigger(0).show();" />
                                                        <Select Handler="this.getTrigger(0).show();" />
                                                        <BeforeQuery Handler="this.getTrigger(0)[this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                                        <TriggerClick Handler="if (index == 0) 
                                                                            { 
                                                                                   this.clearValue(); 
                                                                                   this.getTrigger(0).hide();
                                                                               }" />
                                                        <Select Handler="App.direct.OpenWindow();"></Select>
                                                    </Listeners>
                                                </ext:ComboBox>
                                            </Items>
                                        </ext:FieldContainer>
                                    </Items>
                                </ext:Toolbar>
                            </DockedItems> 
                        </ext:Panel>                                
                    </Items>
                </ext:Viewport>                
    
                <ext:Window ID="Window1" runat="server"
                Title="Test"
                Icon="Table"
                Modal="true"
                Width="332"
                Height="400"
                Collapsible="true"
                Hidden="true"
                Layout="Fit" Closable="false">
                <Items>
                    <ext:FormPanel ID="FormPanel1" runat="server" BodyPadding="10" Height="300" Width="350" MarginSpec="0 5 5 5">                    
                        <Items>
                            
                        </Items>
                    </ext:FormPanel>
                </Items>
                <Tools>
                    <ext:Tool ToolTip="Close" CustomType="my-close" Handler="owner.ownerCt.close();" Width="19" Height="19" />
                </Tools>
            </ext:Window>
            </form>
        </body> 
    </html>

    Thanks a lot.

    Best Regards.
    Last edited by opendat2000; Apr 16, 2015 at 12:41 PM.
  8. #8
    Thank you.

    You should replace
    StoreID = str.ID
    wtih
    Store = { str }
    Also a ModelField's Name cannot contain white spaces.

    Please replace "Columna 1" and "Columna 2" with "Columna1" and "Columna2".
  9. #9
    Thanks a lot,


    Now I can see the values from the store.


    Please close the thread.


    Best Regards.

Similar Threads

  1. [CLOSED] Creating Combobox + Store in CodeBehind
    By trezv in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Mar 12, 2015, 1:41 PM
  2. [CLOSED] Load combobox's store
    By romeu in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jan 11, 2013, 1:50 PM
  3. [CLOSED] How to create and load datasource ( Store ) dynamically in MVC
    By pawangyanwali in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Oct 29, 2012, 10:55 AM
  4. Replies: 0
    Last Post: Mar 31, 2012, 9:10 AM
  5. [CLOSED] Create records in store combobox
    By softmachine2011 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Dec 19, 2011, 9:28 AM

Tags for this Thread

Posting Permissions