[CLOSED] ComboBox / Store / DataSource : Store.DataSource is NULL

  1. #1

    [CLOSED] ComboBox / Store / DataSource : Store.DataSource is NULL

    Hey,

    in a UserControl I have a number of ComboBoxes that each has its own Store.

    I populate those Stores on Page_Load and that works fine. The UserControl is placed on a Page, and when pressing a button the Page I show a Window with my UserControl on it.

    At that point I want to check and see if the Stores have exactly 1 item, and if so set the ComboBox to selected the first item.

    First I went for the ComboBox.Items, but that seems to always have zero elements. I then moved on to look at the Stores for the ComboBoxes and did like this (the Set-method is called in a Property setter, so the Page calls theUserControl.MyProperty = 123; and the setter then calls Set):

    private void Set()
    {
        if ( ((object[])Store_1.DataSource).Length == 1)
            ComboBox_1.SelectedIndex = 0;
        else
            ComboBox_1.SelectedItem.Value = null;
    }
    However, the DataSource is null. My wild guess is that is has something to do with ViewState?

    Note: i know for sure that the Store is populated with values, since if I just remove the code above it all works as expected, ie the ComboBoxes has its values etc.
    Last edited by Daniil; May 02, 2011 at 10:27 AM. Reason: [CLOSED]
  2. #2
    Hi,

    How do you populate the stores? Where and when do you call the posted code?

    Also please read:
    http://forums.ext.net/showthread.php?10705
  3. #3
    I populate the Stores in the Page_Load, like this:

    if (!Page.IsPostBack)
    {
        LoadStore_1();
    }
    
    public void LoadStore_1()
    {
        List<object> myData = new List<object>();
        foreach (uint id in legs)
        {
            MyObject mo = GetMyObject(id);
            myData.Add(new object[] { mo.Id, mo.ObjectName });
        }
    
        Store_1.DataSource = legTemp;
        Store_1.DataBind();
    }
    So this is done on Page_Load. Then I press a button, a property in the UserControl (that the above code is from) is assigned and in the setter method (as described in #1) calles the Set()-method. But then the Store_1.DataSource = null.

    Ahh! Thanks for the link! I actually remember doing that you suggest in #4 before, but forgot all about it.

    But the question is then: do I have to post the whole store back? There is no way for me to detect in my Set()-method if the ComboBox (or Store) only have 1 element?
  4. #4
    Yes, DataSource is null during DirectEvent, because you don't assigned it during DirectEvent.
    if (!Page.IsPostBack)
    I would suggest you to pass Store's count as DirectEvent's extra parameter (via ExtraParams).
  5. #5
    hmm, i normally never use DirectEvent, always DirectMethods.

    What is the difference between the two? DirectMethods are very easy to create and call...
  6. #6
    Please follow
    http://forums.ext.net/showthread.php?12613

    You could pass extra parameters using DirectMethod as well.
  7. #7
    Ok, I will look into that then...

Similar Threads

  1. Replies: 3
    Last Post: Apr 11, 2012, 7:43 AM
  2. Replies: 5
    Last Post: Feb 01, 2012, 11:54 AM
  3. Store and clear datasource
    By glenh in forum 1.x Help
    Replies: 0
    Last Post: Oct 20, 2010, 5:18 AM
  4. Replies: 0
    Last Post: Jun 26, 2009, 11:32 AM
  5. why the DataSource of the store is null
    By animalisme in forum 1.x Help
    Replies: 2
    Last Post: Jun 22, 2009, 3:04 AM

Tags for this Thread

Posting Permissions