[CLOSED] Combobox, StoreId and set value in code behind

  1. #1

    [CLOSED] Combobox, StoreId and set value in code behind

    Hi All,

    May be a silly question but I didn't find how to answer on here on forum. I have a store which is populated in codebehind and combobox which is having StoreID set to this store. My question is how to setup selected value in code behind? Here a code:

    <ext:FormPanel ItemID="AccountFormPanel" Url="/Membership/SubmitRegistration" runat="server" BodyStyle="background:transparent;" Padding="5" Layout="AnchorLayout" Border="false" DefaultAnchor="100%">
      <Bin>
        <ext:Store ID="CompanyCountryStore" runat="server">
            <Model>
                <ext:Model runat="server" IDProperty="Id">
                    <Fields>
                        <ext:ModelField Name="Id" />
                        <ext:ModelField Name="Name" />
                        <ext:ModelField Name="Code" />
                        <ext:ModelField Name="CodeString" />
                        <ext:ModelField Name="Domain" />
                    </Fields>
                </ext:Model>
            </Model>
        </ext:Store>
      </Bin>
      <Items>
     <ext:ComboBox ID="CompanyCountryId" StoreID="CompanyCountryStore" runat="server" ValueField="Id" DisplayField="Name" Editable="false" TypeAhead="true" ForceSelection="true" SelectOnFocus="true" FieldLabel="Country" EmptyText="Please, select" MinChars="1" Flex="1" SimpleSubmit="true" />
          </Items>
        </ext:FieldSet>
      </Items>
    </ext:FormPanel>
    The store is populated like this:

    <script runat="server">
        public void OnPage_Load()
        {
          CompanyCountryStore.DataSource = CountryContainer.GetItemsList();
          CompanyCountryStore.DataBind();
        }
    </script>
    How I can assign selected valut to my combox in code behind? I tried CompanyCountryId.SetValue("F0B385AB-780D-47D6-AB68-2BDC9FBA2FF0") but this doesn't work.

    Thanks,
    Alexander
    Last edited by Daniil; Apr 24, 2013 at 4:19 PM. Reason: [CLOSED]
  2. #2
    Hi Alexander,

    Please use the SetValue method during an AJAX request only (DirectEvent or DirectMethod).

    To set up initially selected items during Page_Load, please populate a ComboBox's SelectedItems collection.
  3. #3
    Hi Daniil,

    Quote Originally Posted by Daniil View Post
    Hi Alexander,

    Please use the SetValue method during an AJAX request only (DirectEvent or DirectMethod).

    To set up initially selected items during Page_Load, please populate a ComboBox's SelectedItems collection.
    I tired to use such construction during Page_Load but it doesn't work

    CompanyCountryId.SelectedItems.Add(new Ext.Net.ListItem("F0B385AB-780D-47D6-AB68-2BDC9FBA2FF0"));
    As far I see the problem is related that I am defining a store using StoreID but not defining items like this

          CompanyCountryId.Items.Add(new Ext.Net.ListItem("DE", "F0B385AB-780D-47D6-AB68-2BDC9FBA2FF0"));
          CompanyCountryId.Items.Add(new Ext.Net.ListItem("PL", "F0B385AB-780D-47D6-AB68-2BDC9FBA2F11"));
          CompanyCountryId.Items.Add(new Ext.Net.ListItem("IT", "F0B385AB-780D-47D6-AB68-2BDC9FBA2F22"));
    Because in this case SelectedItems works.


    Alexander
    Last edited by Svr77; Apr 24, 2013 at 2:58 PM.
  4. #4
    Please try:
    CompanyCountryId.SelectedItems.Add(new Ext.Net.ListItem((object)"F0B385AB-780D-47D6-AB68-2BDC9FBA2FF0"));
  5. #5
    Thanks, this works! You rock!!!

    Alexander

Similar Threads

  1. [CLOSED] Grid ListFilter with StoreID, ValueField?
    By prointernet in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Nov 22, 2012, 2:28 PM
  2. [CLOSED] Setting StoreID on GridFilter to IFrame location
    By peter.campbell in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jul 27, 2012, 1:39 PM
  3. [CLOSED] ListFilter with a StoreID
    By SFritsche in forum 1.x Legacy Premium Help
    Replies: 14
    Last Post: Oct 08, 2010, 1:51 PM
  4. Comboboxes with same StoreID problem
    By vostro1700 in forum 1.x Help
    Replies: 2
    Last Post: Jul 31, 2009, 3:56 PM
  5. problem with multiple dropdownlists using the same storeid
    By LeeTheGreek in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Jan 22, 2009, 7:34 AM

Tags for this Thread

Posting Permissions