[CLOSED] Problem setting value iconcombobox in code

  1. #1

    [CLOSED] Problem setting value iconcombobox in code

    Hi,

    The current way of setting the value of an iconcombo throws serveral errorsr in the ext.axd:
    <!-- CSS -->
    <style type="text/css">
            .icon-combo-item
            {
                background-repeat: no-repeat !important;
                background-position: 3px 50% !important;
                padding-left: 24px !important;
            }
    </style>
     
    <!-- Store -->
    <ext:store id="strGeslacht" runat="server">
            <reader>
                <ext:arrayreader>
                    <fields>
                        <ext:recordfield name="iconCls" />
                        <ext:recordfield name="name" />
                    </fields>
                </ext:arrayreader>
            </reader>
    </ext:store>
     
     
    <!-- combobox -->
     <ext:combobox allowblank="false" fireselectonload="true" id="cmbGeslacht" runat="server"
                                            storeid="strGeslacht" flex="1" editable="false" displayfield="name" valuefield="name"
                                            mode="Local" triggeraction="All" emptytext="-- maak keuze --" note="Geslacht">
     <template id="Template1" runat="server">
       <html>
              <tpl for=".">
                      <div class="x-combo-list-item icon-combo-item {iconCls}">
                              {name}
                             </div>
                     </tpl>
      </html>
      </template>
            <listeners>
             <select handler="this.setIconCls(record.get('iconCls'));" />
            </listeners>
     </ext:combobox>
    CODEBEHIND:

    // Pageload:
     
    /// <summary>
        /// Combobox geslacht vullen
        /// </summary>
        public void populateGeslacht()
        {
            strGeslacht.DataSource = new object[]
            {
                new object[] { ResourceManager.GetIconClassName(Icon.Male), "Man"},
                new object[] { ResourceManager.GetIconClassName(Icon.Female), "Vrouw"},
            };
            strGeslacht.DataBind();
            ResourceManager1.RegisterIcon(Icon.Male);
            ResourceManager1.RegisterIcon(Icon.Female);
        }
     
    // The problem lies here when using data from the database. I'm trying to set the selected value:
     
    cmbGeslacht.SetValue("Man"); // --> several errors in ext.axd --> White empty window
    It worked some svn versions before. Somebody pointed me to the problem.

    Martin
    Last edited by Daniil; May 31, 2011 at 10:44 AM. Reason: [CLOSED]
  2. #2
    Hi Martin,

    Do you mean that before updating .SetValue() set an icon also in the example below?

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                this.Store1.DataSource = new object[]
                {
                    new object[] { ResourceManager.GetIconClassName(Icon.Male), "Man"},
                    new object[] { ResourceManager.GetIconClassName(Icon.Female), "Vrouw"},
                };
                this.Store1.DataBind();
                this.ResourceManager1.RegisterIcon(Icon.Male);
                this.ResourceManager1.RegisterIcon(Icon.Female);
            }
        }
    
        protected void SetValue(object sender, DirectEventArgs e)
        {
            this.ComboBox1.SetValue("Man");
        }
    </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 runat="server">
        <title>Ext.Net Example</title>
        <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 runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            <ext:Store ID="Store1" runat="server">
                <Reader>
                    <ext:ArrayReader>
                        <Fields>
                            <ext:RecordField Name="iconCls" />
                            <ext:RecordField Name="name" />
                        </Fields>
                    </ext:ArrayReader>
                </Reader>
            </ext:Store>
            <ext:ComboBox 
                ID="ComboBox1" runat="server"
                StoreID="Store1" 
                Editable="false" 
                DisplayField="name" 
                ValueField="name"
                Mode="Local">
                <Template runat="server">
                    <Html>
                        <tpl for=".">
                            <div class="x-combo-list-item icon-combo-item {iconCls}">
                              {name}
                            </div>
                        </tpl>
                    </Html>
                </Template>
                <Listeners>
                    <Select Handler="this.setIconCls(record.get('iconCls'));" />
                </Listeners>
            </ext:ComboBox>
            <ext:Button runat="server" Text="ComboBox1.SetValue('Man');" OnDirectClick="SetValue" />
        </form>
    </body>
    </html>
  3. #3
    Mmmm..think my problem is somewhere else.

    It seems thought that the right value is selected, but without the right icon :) (your example)

    Martin
  4. #4
    Well not really true. I try to set the value in code behind.
    Well, I also set in code behind.

    To make the question simple. How do I set the value from codebehind :) after the combobox is databinded.
    After initial Page_Load or, for example, during DirectEvent?

    1. During Page_Load:
    this.ComboBox1.SelectedItem.Value = "Man";
    +
    FireSelectOnLoad="true"
    works.

    2. During DirectEvent:
    this.ComboBox1.SetValueAndFireSelect("Man");
    As far as I know there was no change rather long ago.

Similar Threads

  1. [CLOSED] DropDownField setting value from code-behind
    By kenanhancer in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Dec 15, 2011, 7:29 AM
  2. Replies: 2
    Last Post: May 13, 2011, 7:06 AM
  3. [CLOSED] Setting Combobox value in code behind
    By iansriley in forum 1.x Legacy Premium Help
    Replies: 9
    Last Post: Dec 15, 2010, 7:35 PM
  4. [CLOSED] Setting Store OnRefreshData in code behind
    By deejayns in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Dec 02, 2010, 3:30 PM
  5. Code behind setting Title property on portlet fails
    By netwearcdz in forum 1.x Help
    Replies: 3
    Last Post: Jan 15, 2010, 3:36 PM

Posting Permissions