[CLOSED] Simple select Dynamic Combo

  1. #1

    [CLOSED] Simple select Dynamic Combo

    Doing something wrong. Not sure what. Want to select the item with the 90720 value.

    <%@ Page Language="C#" %>
     
    <script runat="server">
     
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                createKeuzeLijst().AddTo(fpTest);
                preselectValue();
            }
        }
     
        public ComboBox createKeuzeLijst()
        {
            const int nVeldID = 1;
            const string cVeldNaam = "TestField";
            const string cVeldOmschrijving = "TestDescription";
            ComboBox cb = new ComboBox
            {
                ID = string.Format("cb{0}", cVeldNaam),
                ToolTip = cVeldOmschrijving,
                FieldLabel = cVeldNaam,
                ValueField = "cItemWaarde",
                DisplayField = "cItemText",
                AnchorHorizontal = "100%",
                EmptyText = "-- maak keuze --"
            };
     
            AddItems(cb, nVeldID);
            return cb;
        }
     
        public void AddItems(ComboBox cb, Int32 nVeldId)
        {
            Dictionary<String, String> dic = new Dictionary<string, string>();
            dic.Add("99999", "99999 - Ford Rent actie auto");
            dic.Add("90720", "90720 - Ford Rent ondersteuning");
            dic.Add("90750", "90750 - Incentive ondersteuning");
            foreach (KeyValuePair<string, string> entry in dic)
            {
                cb.Items.Add(new Ext.Net.ListItem(entry.Key, entry.Value));
            }
        }
     
        public void preselectValue()
        {
            ComboBox cb = X.GetCmp<ComboBox>("cbTestField");
            cb.SelectedItems.Add(new Ext.Net.ListItem { Value = "90720", Mode = ParameterMode.Raw });
            cb.UpdateSelectedItems();
        }
     
    </script>
     
    <!DOCTYPE html>
     
    <html>
    <head runat="server">
        <title>Dynamic combo</title>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:FormPanel runat="server" ID="fpTest" />
        </form>
    </body>
    </html>
    Last edited by Daniil; Mar 10, 2015 at 9:56 AM. Reason: [CLOSED]
  2. #2
    Hi Martin,

    It appears I can select the item with the 90720 without any problem. Could you, please, clarify what is happening for you?
  3. #3
    Hi Daniil,

    So this code is working for you ? I just see no selected items in my combo. (combo is filled, but no item selected)

    What I mean is that the item must be preselected with this code. But it is not.

    Will update from SVN and try again. I probably use older set.

    Martin
    Last edited by CarWise; Mar 09, 2015 at 1:00 PM.
  4. #4
    So this code is working for you ?
    Yes, it is definitely working for me. The item gets selected.

    Will update from SVN and try again. I probably use older set.
    Yes, please. Please also try in different browsers. As for IE, please ensure the compatibility node is switched off.
  5. #5
    Updated SVN

    Tried in several browsers, but I don't get a selected item.

    The dropdown is populated with the right items.

    I don't have a clue why the same code it's working on your side.. and not on mine..

    Martin
  6. #6
    Generated HTML

    <!DOCTYPE html>
    <html>
    <head>
    <link type="text/css" rel="stylesheet" href="/extjs/resources/ext_theme_gray/ext-theme-gray-all-debug-embedded-css/ext.axd?v=27984" id="ext-theme" />
    <link type="text/css" rel="stylesheet" href="/extnet/resources/css/extnet-all-debug-embedded-css/ext.axd?v=27984" id="extnet-styles" />
    <script type="text/javascript" src="/extjs/ext-all-dev-js/ext.axd?v=27984"></script>
    <script type="text/javascript" src="/extnet/extnet-all-debug-js/ext.axd?v=27984"></script>
    <script type="text/javascript" src="/extnet/locale/ext-lang-nl-js/ext.axd?v=27984"></script>
    <title>
    Dynamic combo
    </title>
    <script type="text/javascript">
    //<![CDATA[
    Ext.net.ResourceMgr.init({
    id: "ctl03",
    aspForm: "ctl01",
    theme: "gray"
    });Ext.onReady(function(){Ext.create("Ext.form.Panel",{
    id: "fpTest",
    renderTo: "App.fpTest_Container",
    url: unescape("%2ftest%2f"),
    waitMsgTarget: ""
    });Ext.net.ResourceMgr.destroyCmp("App.cbTestField");App.fpTest.add({
    id: "cbTestField",
    xtype: "combobox",
    anchor: "100%",
    fieldLabel: "TestField",
    emptyText: "-- maak keuze --",
    displayField: "cItemText",
    queryMode: "local",
    valueField: "cItemWaarde",
    store: [["99999 - Ford Rent actie auto","99999"],["90720 - Ford Rent ondersteuning","90720"],["90750 - Incentive ondersteuning","90750"]]
    });App.cbTestField.setSelectedItems([{value:90720}]);});
    //]]>
    </script>
    </head>
    <body>
    <form method="post" action="" id="ctl01">
    <div class="aspNetHidden">
    <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
    <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTIwNzE2MjQ0ODdkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYCBQVjdGwwMwUGZnBUZXN0gA6wzzxyVorTu4wCy9zJJwu7HmGr1zqn6QEFoUTvg+Q=" />
    </div>
    <script type="text/javascript">
    //<![CDATA[
    var theForm = document.forms['ctl01'];
    if (!theForm) {
    theForm = document.ctl01;
    }
    function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
    theForm.__EVENTTARGET.value = eventTarget;
    theForm.__EVENTARGUMENT.value = eventArgument;
    theForm.submit();
    }
    }
    //]]>
    </script>
    <div id="App.fpTest_Container"></div>
    <div class="aspNetHidden">
    <input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="80F1723F" />
    <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEdAAIPXqjgT5U+KToa7OFaOdVXNpGzZOwh9RDF3/tMV5ai8yPXVunfitbkn/Ijagi9VVSykaR6iGkAdK7X9BgbQgfY" />
    </div></form>
    <!-- Visual Studio Browser Link -->
    <script type="application/json" id="__browserLink_initializationData">
    {"appName":"Chrome","requestId":"9a9297fdad9046ccb64b9b051ac10be6"}
    </script>
    <script type="text/javascript" src="http://localhost:52111/6409619fc7194...40/browserLink" async="async"></script>
    <!-- End Browser Link -->
    </body>
    </html>
  7. #7
    Sorry, I misunderstood the issue.

    Ok, there is a few changes that should be applied.

    1. .AddTo(), .UpdateSelectedItems(), X.GetCmp<> are supposed to be used only during DirectEvetns or DirectMethods.

    2. ParameterMode.Value should be used here:
    cb.SelectedItems.Add(new Ext.Net.ListItem { Value = "90720", Mode = ParameterMode.Raw });
    3. Also you should switch Key and Value here:
    cb.Items.Add(new Ext.Net.ListItem(entry.Key, entry.Value));
    This appears to be working.
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!X.IsAjaxRequest)
        {
            var cb = createKeuzeLijst();
            preselectValue(cb);
            fpTest.Items.Add(cb);
        }
    }
     
    public ComboBox createKeuzeLijst()
    {
        const int nVeldID = 1;
        const string cVeldNaam = "TestField";
        const string cVeldOmschrijving = "TestDescription";
        ComboBox cb = new ComboBox
        {
            ID = string.Format("cb{0}", cVeldNaam),
            ToolTip = cVeldOmschrijving,
            FieldLabel = cVeldNaam,
            ValueField = "cItemWaarde",
            DisplayField = "cItemText",
            AnchorHorizontal = "100%",
            EmptyText = "-- maak keuze --"
        };
     
        AddItems(cb, nVeldID);
        return cb;
    }
     
    public void AddItems(ComboBox cb, Int32 nVeldId)
    {
        Dictionary<String, String> dic = new Dictionary<string, string>();
        dic.Add("99999", "99999 - Ford Rent actie auto");
        dic.Add("90720", "90720 - Ford Rent ondersteuning");
        dic.Add("90750", "90750 - Incentive ondersteuning");
        foreach (KeyValuePair<string, string> entry in dic)
        {
            cb.Items.Add(new Ext.Net.ListItem(entry.Value, entry.Key));
        }
    }
     
    public void preselectValue(ComboBox cb)
    {
        cb.SelectedItems.Add(new Ext.Net.ListItem { Value = "90720", Mode = ParameterMode.Value });
    }
  8. #8
    Thx Daniil. Still learning :)

Similar Threads

  1. [CLOSED] Simple combo box question
    By rmelancon in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: May 06, 2014, 11:42 AM
  2. [CLOSED] Simple select in Multi Mode Grid view
    By RCM in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Oct 10, 2013, 9:45 PM
  3. Multi combo first time select - problem
    By ssenthil21 in forum 1.x Help
    Replies: 1
    Last Post: Sep 21, 2011, 8:55 AM
  4. [CLOSED] Select the contents of the combo
    By majunior in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jun 24, 2011, 1:46 PM
  5. Replies: 3
    Last Post: May 11, 2010, 10:36 AM

Posting Permissions