Apr 21, 2011, 11:24 PM
[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):
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.
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]