[CLOSED] Problem with Combobox.SelectedItem

  1. #1

    [CLOSED] Problem with Combobox.SelectedItem

    We are having a recurring issue with setting combobox values in our projects. Every now and then we will get different behaviour from setting the selected item by using ComboBox.SelectedItem.Value. Sometimes ComboBox.SelectedItem.Value = "100" works, sometimes it doesn't. Sometimes ComboBox.SetValue("100") works, sometimes it doesn't. Test case below.

    
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="com.bspr.crbspr.pages.WebForm1" %>
    
    <!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></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <ext:ResourceManager ID="rsmMain" runat="server" Theme="Gray">
            </ext:ResourceManager>
    
            <ext:Viewport ID="vwpMain" runat="server">
                <Items>
    
                    <ext:ComboBox runat="server" ID="cmbCDDTabID" FieldLabel="CDD Tab ID" ValueField="CDD_TAB_ID" DisplayField="CDD_TAB_DESC" AnchorHorizontal="99%" AllowBlank="false">
                        <Store>
                            <ext:Store ID="Store1" runat="server" IgnoreExtraFields="false">
                                <Model>
                                    <ext:Model ID="Model1" runat="Server">
                                        <Fields>
                                            <ext:ModelField Name="CDD_TAB_ID" />
                                            <ext:ModelField Name="CDD_TAB_DESC" />
                                        </Fields>
                                    </ext:Model>
                                </Model>
                            </ext:Store>
                        </Store>
                    </ext:ComboBox>
    
                    <ext:Button runat="server" ID="txtTest" Text="TEST">
                        <Listeners>
                            <Click Handler="App.direct.test();"></Click>
                        </Listeners>
                    </ext:Button>
    
                </Items>
            </ext:Viewport>
    
        </div>
        </form>
    </body>
    </html>
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Ext.Net;
    
    namespace com.bspr.crbspr.pages
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                cmbCDDTabID.Store[0].DataSource = new object[] 
                { 
                    new object[] { "0", "none" },
                    new object[] { "100", "item1" },
                    new object[] { "200", "item2" },
                    new object[] { "300", "item3" }
                };
                cmbCDDTabID.Store[0].DataBind();
                cmbCDDTabID.SelectedItem.Index = 0;
            }
    
            [DirectMethod]
            public void test()
            {
                cmbCDDTabID.SelectedItem.Value = "100";
            }
        }
    }
    Last edited by Daniil; Jun 08, 2015 at 10:20 AM. Reason: [CLOSED]
  2. #2
    Hi

    During DirectEvent/DirectMethod you have to use `SetValue` method
    cmbCDDTabID.SetValue("100");
    or call `UpdateSelectedItems` method after changing of SelectedItem(s)
    cmbCDDTabID.SelectedItem.Value = "100";
    cmbCDDTabID.UpdateSelectedItems();

Similar Threads

  1. Replies: 10
    Last Post: May 16, 2014, 4:39 AM
  2. [CLOSED] [2.2] Combobox selecteditem problem
    By John_Writers in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Oct 09, 2013, 12:51 PM
  3. [CLOSED] Problem with selectedItem.value in combobox
    By CarWise in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Sep 10, 2012, 4:35 PM
  4. [CLOSED] Problem to show SelectedItem in Combobox v2.0
    By Oliver in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: May 28, 2012, 3:56 PM
  5. ComboBox SelectedItem according to Value problem
    By juredecman in forum 1.x Help
    Replies: 0
    Last Post: Aug 25, 2010, 8:57 PM

Posting Permissions