[OPEN] Default value in a Combo Box

  1. #1

    [OPEN] Default value in a Combo Box

    Hi i have a combobox which looks like the code example, I have 2 problems with it:
    1. I cant get a default value to be set in the combo.
    2. The user is able to enter a value from the keybord, for example "10", but when i try to fetch the selected value, the selected item is -1. "string strValue = cbTest.Item.[cbTest.SelectedIndex].Text;"

    
    
    
    <ext:ComboBox Width="70" ID="cbTest" runat="server" /> 
    
    
    
    
    for (int i = 1; i <= 40; i++)
    {
        Coolite.Ext.Web.ListItem liItem = new Coolite.Ext.Web.ListItem();
        liItem.Value = i.ToString();
        liItem.Text = i.ToString();
        cbTest.Items.Add(liItem);
    }
    How do I solve this?

    Best regards
    Mikael Jürke
  2. #2

    RE: [OPEN] Default value in a Combo Box

    Hi Mikael,

    The ComboBox class has SelectedValue property. Using this property you can set predefined value

    ComboBox1.SelectedItem.Value = "10";
    Also after postback/ajaxevent you can read selected value and text

    string val = ComboBox1.SelectedItem.Value;
    string txt= ComboBox1.SelectedItem.Text;

  3. #3

    RE: [OPEN] Default value in a Combo Box

    Thanks,
    But if a user types in a value, for example "6" without actually selecting the value, the combo box visually has the value 6 but the selected value is something else. Is there something you can do about this. I think it will be confusing for the users.

    Best regards
    Mikael Jürke
  4. #4

    RE: [OPEN] Default value in a Combo Box

    Hi Mikael,

    yes, you are right, I recommending to set ReadOnly="true" for ComboBox while we solving this problem

    Thanks

Similar Threads

  1. Replies: 6
    Last Post: Aug 25, 2011, 2:13 PM
  2. Open Tab through sub-tab
    By poveron in forum 1.x Help
    Replies: 3
    Last Post: Jul 30, 2010, 8:29 PM
  3. Replies: 3
    Last Post: May 11, 2010, 10:36 AM
  4. Replies: 4
    Last Post: Sep 18, 2009, 9:49 AM
  5. Default value GridFilters
    By juanjo in forum 1.x Help
    Replies: 0
    Last Post: Feb 21, 2009, 5:18 AM

Posting Permissions