[CLOSED] how to binddata to ext:combobox in codebehind with datasource?

  1. #1

    [CLOSED] how to binddata to ext:combobox in codebehind with datasource?

    <ext:ComboBox ID="cb_VouchClassCode" InputWidth="60" runat="server" Cls="mr5">
                                                
    </ext:ComboBox>
    var li = new Ext.Net.ListItem {Text = "car", Value = "c"};
    cb_VouchClassCode.Items.Add(li);
    through above code can do this , but I wonder if there is other way to do this as gridpanel's datasource property?
    Last edited by Daniil; Jun 04, 2013 at 5:08 AM. Reason: [CLOSED]
  2. #2
    Hi @tobros,

    Welcome to the Ext.NET forums!

    You should deal with a ComboBox's Store.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.ComboBox1.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] { "1", "Item 1" },
                    new object[] { "2", "Item 2" },
                    new object[] { "3", "Item 3" }
                };
            }
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:ComboBox 
                ID="ComboBox1" 
                runat="server" 
                DisplayField="text" 
                ValueField="value">
                <Store>
                    <ext:Store runat="server">
                        <Model>
                            <ext:Model runat="server">
                                <Fields>
                                    <ext:ModelField Name="value" />
                                    <ext:ModelField Name="text" />
                                </Fields>
                            </ext:Model>
                        </Model>
                        <Reader>
                            <ext:ArrayReader />
                        </Reader>
                    </ext:Store>
                </Store>
            </ext:ComboBox>
        </form>
    </body>
    </html>
  3. #3
    thanks. I want to autoselect the first listitem, but autoselect property maybe not works corectly.
    <ext:ComboBox ID="cb_VouchClassCode" Editable="False"   InputWidth="120" runat="server" DisplayField="VouchClassName" ValueField="VouchClassCode" Cls="mr5" AutoSelect="True">
                                                <Store>
                                                    <ext:Store runat="server" ID="store_VCC">
                                                        <Model>
                                                            <ext:Model runat="server" IDProperty="VouchClassCode">
                                                                <Fields>
                                                                    <ext:ModelField runat="server" Name="VouchClassCode"></ext:ModelField>
                                                                    <ext:ModelField runat="server" Name="VouchClassName"></ext:ModelField>
                                                                </Fields>
                                                            </ext:Model>
                                                        </Model>
                                                        
                                                    </ext:Store>
                                                </Store>
                                                
    </ext:ComboBox>
                List<Cwzz_VouchClass> ll = vouchClassService.VouchClasses();
                store_VCC.DataSource = ll;
                store_VCC.DataBind();
    how to auto select the first listitem?
  4. #4
    Please define the following for the ComboBox.
    <SelectedItems>
        <ext:ListItem Index="0" />
    </SelectedItems>
    The AutoSelect is for other thing.
    http://docs.sencha.com/extjs/4.2.1/#...cfg-autoSelect

Similar Threads

  1. Binddata dynamic data to Treepanel
    By qlot in forum 1.x Help
    Replies: 0
    Last Post: Aug 04, 2012, 3:50 AM
  2. How to set a DataSource of a ComboBox?
    By rpk2006 in forum 1.x Help
    Replies: 3
    Last Post: Mar 14, 2012, 1:20 PM
  3. [CLOSED] ComboBox / Store / DataSource : Store.DataSource is NULL
    By wagger in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Apr 24, 2011, 10:09 AM
  4. how to apply datasource to combobox
    By moa1961 in forum 1.x Help
    Replies: 1
    Last Post: Dec 21, 2010, 9:58 AM
  5. Replies: 0
    Last Post: Mar 11, 2009, 5:06 AM

Posting Permissions