PDA

View Full Version : [CLOSED] ComboBox.Items.Count shows '0', even after binding data the ComboBox store.



Tarun_Chand
Mar 11, 2013, 9:28 AM
Team,

I have a combobox which is has store mapped to it.

I am binding the data to the store in page_load event, after that i have to select the first item in that combobox, but when i check the item count it shows 0, so i am not able to select the items.

Here below the code snippet.

=========== aspx ================


<ext:Store ID="storeFilterSites" runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="SITE_NAME" />
<ext:ModelField Name="SITE_QUERY_ID" />
<ext:ModelField Name="ONNET_FLAG" />
</Fields>
</ext:Model>
</Model>
</ext:Store>


<ext:ComboBox ID="cmbSiteFilter" MarginSpec="1 5 0 5" runat="server" StoreID="storeFilterSites"
DisplayField="SITE_NAME" TriggerAction="All" ValueField="SITE_QUERY_ID" QueryMode="Remote"
ForceSelection="true" Editable="false" EmptyText="Please Select">
<ListConfig ItemSelector="div.list-item">
<Tpl ID="Tpl3" runat="server">
<Html>
<tpl for=".">
<div class="list-item">
{SITE_NAME}
</div>
</tpl>
</Html>
</Tpl>
</ListConfig>
</ext:ComboBox>


============================

=========== code behind =========


DataTable dtSiteData = objBAL.GetSiteList(requestId);
storeFilterSites.DataSource = dtSiteData;
storeFilterSites.DataBind();

//in the below statement, the count is alway zero.
if (cmbSiteFilter.Items.Count > 0)
{
cmbSiteFilter.Select(0);
}

============================


Please help me in resolving this.


Thanks in advance.

Cheers...

Daniil
Mar 11, 2013, 1:38 PM
Hello Tarun,

A Store's DataBind doesn't populate a ComboBox's Items.

If you need to select the first item initially, please use a ComboBox's SelectedItems property.

<SelectedItems>
<ext:ListItem Index="0" />
</SelectedItems>

Tarun_Chand
Mar 12, 2013, 1:29 PM
Hello Tarun,

A Store's DataBind doesn't populate a ComboBox's Items.

If you need to select the first item initially, please use a ComboBox's SelectedItems property.

<SelectedItems>
<ext:ListItem Index="0" />
</SelectedItems>



Thank you Daniil,

But not all the times I will be selecting the first item, sometimes I have look for the some data in the bound data to the combobox and select it.

Daniil
Mar 12, 2013, 4:37 PM
You can specify Value or Text for a ListItem.

Tarun_Chand
Mar 15, 2013, 4:16 AM
You can specify Value or Text for a ListItem.


Thanks Daniil,

It works for me... It would have been even better if I could see the items in the ComboBox.

You can mark it as closed.


Cheers...

Daniil
Mar 15, 2013, 5:24 AM
It would have been even better if I could see the items in the ComboBox.

Generally, a ComboBox's Items and a Store's DataBind are just different ways to populate a ComboBox. You can use Items or DataBind. If required, you could populate Items manually from a data source.

In some scenarios they - a ComboBox's Items and a Store's DataBind - can be used together. Though I would avoid such scenarios.