[CLOSED] [2.2] Combobox selecteditem problem

  1. #1

    [CLOSED] [2.2] Combobox selecteditem problem

    Hi,
    with combobox I can't select the item by value.
    The follow code explain the example:
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack && !X.IsAjaxRequest)
                {
                    for (int i = 0; i < 10; i++)
                    {
                        cb.Items.Add(new Ext.Net.ListItem()
                        {
                            Text = "Value of :" + i.ToString(),
                            Value = i.ToString()
                        });
                    }
                }
            }
            protected void btn_Click(object sender, DirectEventArgs e)
            {
                Ext.Net.ListItem li = new Ext.Net.ListItem(2);
                li.Mode = ParameterMode.Raw;
                
                cb.SelectedItems.Add(li);
                //cb.SelectedItem.Value = "2";
                //cb.SetValue(2);
            }
        
        </script>
        <form id="form1" runat="server">
         <ext:ResourceManager ID="ResourceManager1" runat="server" Theme="Gray" CleanResourceUrl="false" RethrowAjaxExceptions="true">
            </ext:ResourceManager>
          
            <ext:ComboBox ID="cb" runat="server" Editable="false"  Width="400" AllowBlank="false" >
                            
                        </ext:ComboBox>
            <ext:Button runat="server" Text="select">
                <DirectEvents>
                    <Click OnEvent="btn_Click"></Click>
    
                </DirectEvents>
    
            </ext:Button>
    
        </form>
    </body>
    </html>
    I try to use tree method to select by value.
    1. To add the listitem to SelectedItems collection - not works
    2. Use SelectedItem.Value - not works
    3. Use setValue method - This show the vallue and not select by value (The combo show 2 intead of "Value of : 2")

    Can you help me?
    thanks
    Last edited by Daniil; Oct 09, 2013 at 1:03 PM. Reason: [CLOSED]
  2. #2
    Hi John,

    There are two issues.

    1. If you deal with a SelectedItems collection during a DirectEvent, you should call:
    cb.UpdateSelectedItems();
    after modifications.

    2. There must be matching in types. You bind strings as items' values, but want to select "2" of int type.

    So, this is working.
    protected void btn_Click(object sender, DirectEventArgs e)
    {
        Ext.Net.ListItem li = new Ext.Net.ListItem("2");
        cb.SelectedItems.Add(li);
        cb.UpdateSelectedItems();
    }
  3. #3
    Its works.

    Thanks

Similar Threads

  1. Replies: 10
    Last Post: May 16, 2014, 4:39 AM
  2. [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
  3. [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
  4. Replies: 2
    Last Post: Mar 03, 2012, 3:33 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