ComboBox SetValueAndFireSelect

  1. #1

    ComboBox SetValueAndFireSelect

    On page load - server side - I am setting the below:



    this.ComboBox1.SetValueAndFireSelect(Session["contractID"].ToString());
    The combobox is using a template (similar to the example) to display the contents/data - the problem is that the valuefield, on page load, is shown in the combobox instead of the text and the the select does not seem to be firing?</p>
  2. #2

    RE: ComboBox SetValueAndFireSelect

    Hi Tbaseflug,

    Did you ever managed to solve this problem?
    I may be doing something wrong, but seems that when using the ComboBox as the Search example and trying to select a value it shows the valuefield and not the text.

    To reproduce it, just grab the Search sample for Plants and try to select the default value on the server using the SetValueAndFireSelect method.

    Can someone help, please?

    Thanks.
    Leo.
  3. #3

    RE: ComboBox SetValueAndFireSelect

    Hi guys,

    Please note that if you see value in combo instead text then it is mean that you tried to set value when store is not loaded yet (or the store doesn't contain such value)


    Tbaseflug: try the folllowing
    - set FireSelect&#111;nload="true" for combo (if you need to fire select event after initial value was set)
    - call
    Combo1.AddScript("{0}.setInitValue(\"{1}\");", Combo1.ClientID, YourValue);

    ljcorreia: about Search example. In that example the store doesn't contains any value until you type something. Therefore when you try to set value programatically the store can't mapping value with text because nothing to mapping. Try the following code (I assume that DisplayField="Botanical" and ValueField="Common")
    ComboBox1.AddScript("{0}.setInitValue(\"{1}\");", ComboBox1.ClientID, "Columbine");
    ComboBox1.AddScript("{0}.doQuery('Columbine');", ComboBox1.ClientID);
  4. #4

    RE: ComboBox SetValueAndFireSelect

    Hi vladimir,

    Thank you very much for your response and example. It has clarified some concepts.

    Combo:
    Everything ok with the combo now. The .SetInitValue() did the trick although I could not find it in the ExtJs API Doc. Is it a method that you guys added?

    Search:
    I understood your point about the Search where the store doesn't contains any value until you type something. However the approach you used calling doQuery() is not exactly what I am expecting. It will call the handler and obviously show the results template, right?

    In fact what I need it something more simple. I need to set the initial value and don't need to load the store when the page first load (IsPostBack). All I need is the Text and Value been set to a default initial value.
    I did achieve this using your helpful clues, but I am not sure if I am doing the right thing. So let me put some code to explain it better:

    if (Ext.IsAjaxRequest)
    {
    ...
       ComboBox1.AddItem("Text", "Value");
       ComboBox1.SetValue("Value");
    }
    ...
    This would do the trick for me, but I am sure is my misunderstanding and it is not right what I am doing.
    If I don't put the above code, let say, just execute exactly how you suggested the value will be displayed, but the text and valuefield will contain "Columbine".

    ComboBox1.AddScript("{0}.setInitValue(\"{1}\");", ComboBox1.ClientID, "Columbine");
    Is there another way to Add an Item(Text/Value) using AddScript or something?
    The other thing I don't understand is that if I put a breakpoint on the store handler class where the data is being selected, it does not contains the filter text (initial value) when the first page load.

    Can you spot what I am doing wrong?

    Thanks
    Leo.
  5. #5

    RE: ComboBox SetValueAndFireSelect

    Hi,

    My code is performing the following:
    - set value initial value (will be displayed value because the store is empty still)
    - make request to load data, after data loading the text will be displayed

    Please note that if no data in the store then you can't set any value for combo (even initial value). Your trick with adding inner item at initial page load is the right thing

    "The
    other thing I don't understand is that if I put a breakpoint on the
    store handler class where the data is being selected, it does not
    contains the filter text (initial value) when the first page load.
    "

    Do you have AutoLoad="true" for store? Just store try to perform request to get data if Auto="true" (default value). In this case there is no any query value because the request was initiated by store (not combobox)
  6. #6

    RE: ComboBox SetValueAndFireSelect

    Hi vladimir,

    Thank you very much for your explanation and patience.

    Yes, I am using AutoLoad="true" and this explains.

    From my side this thread could be marked as CLOSED.

    Thanks
    Leo.

Similar Threads

  1. Replies: 4
    Last Post: Nov 30, 2011, 5:25 AM
  2. Replies: 4
    Last Post: Sep 28, 2011, 8:57 AM
  3. Replies: 1
    Last Post: Apr 17, 2011, 1:21 PM
  4. ComboBox - setValueAndFireSelect
    By Tbaseflug in forum 1.x Help
    Replies: 1
    Last Post: Apr 22, 2009, 4:23 PM
  5. Replies: 10
    Last Post: Mar 11, 2009, 6:15 AM

Posting Permissions