[CLOSED] Problem to list through item combo from code behind

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] Problem to list through item combo from code behind

    Hello

    Basicaly I want to do that:

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            var store = this.ComboBox1.GetStore();
            
            store.DataSource = new object[]
            {
                new object[] { ResourceManager.GetIconClassName(Icon.FlagFr), "France"},
                new object[] { ResourceManager.GetIconClassName(Icon.FlagCa), "Canada"},
                new object[] { ResourceManager.GetIconClassName(Icon.FlagDe), "Germany"},
                new object[] { ResourceManager.GetIconClassName(Icon.FlagUs), "United States"},
                new object[] { ResourceManager.GetIconClassName(Icon.FlagIt), "Italy"}
            };
            
            store.DataBind();
    
            this.ResourceManager1.RegisterIcon(Icon.FlagFr);
            this.ResourceManager1.RegisterIcon(Icon.FlagCa);
            this.ResourceManager1.RegisterIcon(Icon.FlagDe);
            this.ResourceManager1.RegisterIcon(Icon.FlagUs);
            this.ResourceManager1.RegisterIcon(Icon.FlagIt);
            
            
            for (int i = 0; i < this.ComboBox1.Items.Count-1; i++)
                {
                    //do something
                }
            
        }
    </script>
    
    <html>
    <head id="Head1" runat="server">
        <title>IconCombo - Ext.NET Examples</title>
        <link href="/resources/css/examples.css" rel="stylesheet" type="text/css" />
        <style type="text/css">
             .icon-combo-item {
                background-repeat   : no-repeat !important;
                background-position : 3px 50% !important;
                padding-left        : 24px !important;
            }
        </style>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            
            <h1>Render an Icon in ComboBox data items</h1>
    
            <ext:ComboBox 
                ID="ComboBox1" 
                runat="server"
                Width="250"
                Editable="false"
                DisplayField="name"
                ValueField="name"
                QueryMode="Local"
                TriggerAction="All"
                EmptyText="Select a country...">
                <Store>
                    <ext:Store ID="Store1" runat="server">
                        <Model>
                            <ext:Model ID="Model1" runat="server">
                                <Fields>
                                    <ext:ModelField Name="iconCls" />
                                    <ext:ModelField Name="name" />
                                </Fields>
                            </ext:Model>
                        </Model>            
                    </ext:Store>
                </Store>
                <ListConfig>
                    <ItemTpl ID="ItemTpl1" runat="server">
                        <Html>
                            <div class="icon-combo-item {iconCls}">
                                {name}
                            </div>
                        </Html>                    
                    </ItemTpl>
                </ListConfig>
                <Listeners>
                    <Change Handler="if(this.valueModels.length>0){this.setIconCls(this.valueModels[0].get('iconCls'));}" />
                </Listeners>  
            </ext:ComboBox>    
        </form>
    </body>
    </html>
    (see last lines of the Page_Load function)

    But items.count=0, so how to list all items in the combo?

    I try to look at store level too, but found nothing until now.
    Last edited by Daniil; Oct 15, 2012 at 5:58 PM. Reason: [CLOSED]
  2. #2
    Hi @feanor91,

    DataBind() doesn't populate the ComboBox Items collection. Generally, there can be any number of fields which you can bind to the Store, but ListItem can contain only two - Text and Value. So, I can't see anyway to support such behavior.

    You should iterate the DataSource.
  3. #3
    OK,

    But the databind is for this example, in my code I use a store to populate the combo (from an xmlp file, so I use an xml reader), is it the same behaviour?
  4. #4
    Do you load an XML file using AjaxProxy?

    If so, then it is loaded via an AJAX request, so, the loaded data cannot be accessible on Page_Load.

    You could send required data to server from a client when it is already loaded. Another approach is reading an XML file manually in Page_Load.
  5. #5
  6. #6
    Quote Originally Posted by feanor91 View Post
    I have others combo in previous project that works like a charm. The only difference betwenn them and here is that here data came from an xml file and not a database.
    Well, if you don't populate Items explicitly, they won't be presented.

    How do you bind a data from a database?
  7. #7
    Like in the exemple I post upward, I call an aspx page taht return a JSON file
  8. #8
    Using AjaxProxy? And are you saying that the ComboBox Items collection is populated?

    Do I understand correctly?
  9. #9
    Hum...I check, and no, you'r right, the combobox I think of, contains months, and I poupulated by hand, in fact, I never iterate through such a combox.

    But, how can I get the datasource in that case?
  10. #10
    Well, the answer is here:

    Quote Originally Posted by Daniil View Post
    Do you load an XML file using AjaxProxy?

    If so, then it is loaded via an AJAX request, so, the loaded data cannot be accessible on Page_Load.

    You could send required data to server from a client when it is already loaded. Another approach is reading an XML file manually in Page_Load.
Page 1 of 2 12 LastLast

Similar Threads

  1. [CLOSED] Cycle Button list item images
    By musher in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jun 20, 2012, 9:02 PM
  2. [CLOSED] Combo list adjust
    By softmachine2011 in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Jun 15, 2012, 2:07 PM
  3. [CLOSED] Combo box list alignment
    By yobnet in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 10, 2010, 6:14 AM
  4. Inconsistent height on div.x-combo-list-inner
    By dlouwers in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Jan 14, 2009, 3:17 PM
  5. Selecting an item in a combo box in code
    By antonyn in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Dec 17, 2008, 6:21 AM

Posting Permissions