[CLOSED] How to select a ComboBox option in Direct Method?

  1. #1

    [CLOSED] How to select a ComboBox option in Direct Method?

    Hi,

    I'm trying to port some existing 1.x code and curious how to make a ComboBox selection on the server in DirectMethod context. Please consider the code sample below and advise what adjustments are needed.

    <%@ 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)
            {
                var list = new List<object>
                {
                    new {CountryName = "Canada", CountryID = 1},
                    new {CountryName = "Great Britain", CountryID = 2},
                    new {CountryName = "United States", CountryID = 3}
                };
    
                this.Store1.DataSource = list;
                this.Store1.DataBind();
    
                ComboBox1.SelectedItems.Add(new Ext.Net.ListItem(2));
            }
        }
    
        [DirectMethod]
        public void SelectCountry()
        {
            ComboBox1.SelectedItems.Clear();
            ComboBox1.SelectedItems.Add(new Ext.Net.ListItem(1));
        }
    
    </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 id="Head1" runat="server">
        <title>Ext.Net 2.x</title>
        <script type="text/javascript">
            var selectCountry = function () {
                X.SelectCountry();
            };
        </script>
        <ext:ResourcePlaceHolder ID="ResourcePlaceHolder1" runat="server" Mode="Script" />
        <ext:ResourcePlaceHolder ID="ResourcePlaceHolder2" runat="server" Mode="Style" />
    </head>
    <body>
        <form id="Form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" DirectMethodNamespace="X">
        </ext:ResourceManager>
        <ext:Viewport runat="server" Layout="FitLayout">
            <Items>
                <ext:Panel runat="server">
                    <Items>
                        <ext:ComboBox ID="ComboBox1" runat="server" DisplayField="CountryName" ValueField="CountryID"
                            TypeAhead="true" Editable="true" MinChars="2" SelectOnFocus="true" EmptyText="Select Country..."
                            FieldLabel="Select Country" QueryMode="Local">
                            <Store>
                                <ext:Store ID="Store1" runat="server">
                                    <Model>
                                        <ext:Model ID="Model1" runat="server" IDProperty="CountryID">
                                            <Fields>
                                                <ext:ModelField Name="CountryName" />
                                                <ext:ModelField Name="CountryID" />
                                            </Fields>
                                        </ext:Model>
                                    </Model>
                                </ext:Store>
                            </Store>
                        </ext:ComboBox>
                        <ext:Button runat="server" Text="Select Country">
                            <Listeners>
                                <Click Handler="selectCountry();">
                                </Click>
                            </Listeners>
                        </ext:Button>
                    </Items>
                </ext:Panel>
            </Items>
        </ext:Viewport>
        </form>
    </body>
    </html>
    Last edited by Daniil; Aug 14, 2013 at 5:46 PM. Reason: [CLOSED]
  2. #2
    Hi Vadym,

    Please just add an UpdateSelectedItems call.
    [DirectMethod]
    public void SelectCountry()
    {
        ComboBox1.SelectedItems.Clear();
        ComboBox1.SelectedItems.Add(new Ext.Net.ListItem(1));
        ComboBox1.UpdateSelectedItems();
    }
    Another ways are:
    this.ComboBox1.Value = 1;
    or
    this.ComboBox1.SetValue(1);
  3. #3
    Thanks Daniil! I like this.ComboBox1.SetValue(1); the most for its brevity :) Please close this question down.

Similar Threads

  1. [CLOSED] Output Cache issue with Direct Method / Direct Event
    By amitpareek in forum 1.x Legacy Premium Help
    Replies: 18
    Last Post: Mar 01, 2013, 5:03 AM
  2. Replies: 4
    Last Post: Jul 12, 2012, 2:29 PM
  3. Direct method and direct event over SSL?
    By dimitar in forum 1.x Help
    Replies: 0
    Last Post: Oct 08, 2011, 8:09 PM
  4. ComboBox stays open after Select Direct Event
    By adamdc78 in forum 1.x Help
    Replies: 2
    Last Post: Sep 24, 2011, 10:01 PM
  5. Select all option in MultiCombo
    By skrishnasamy in forum 1.x Help
    Replies: 0
    Last Post: Aug 12, 2010, 7:02 AM

Tags for this Thread

Posting Permissions