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

  1. #1

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

    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...
    Last edited by Baidaly; Mar 15, 2013 at 5:04 AM. Reason: [CLOSED]
  2. #2
    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>
  3. #3
    Quote Originally Posted by Daniil View Post
    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.
  4. #4
    You can specify Value or Text for a ListItem.
  5. #5
    Quote Originally Posted by Daniil View Post
    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...
  6. #6
    Quote Originally Posted by Tarun Chand View Post
    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.

Similar Threads

  1. Data not binding into ComboBox
    By nagesh in forum 1.x Help
    Replies: 5
    Last Post: Jul 12, 2012, 3:35 PM
  2. Replies: 0
    Last Post: May 15, 2012, 6:22 PM
  3. Replies: 0
    Last Post: Oct 25, 2011, 11:02 AM
  4. Count items in a ComboBox?
    By Tbaseflug in forum 1.x Help
    Replies: 1
    Last Post: Nov 18, 2009, 12:25 PM
  5. Two binding combobox not work by items way
    By animalisme in forum 1.x Help
    Replies: 1
    Last Post: Sep 28, 2009, 4:30 AM

Tags for this Thread

Posting Permissions