[CLOSED] Creating Combobox + Store in CodeBehind

  1. #1

    [CLOSED] Creating Combobox + Store in CodeBehind

    Hi,

    I've been looking this over and over again for way too long, what am I doing wrong here? It looks like combobox has 3 items in it, but it doesn't display them.

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm13.aspx.cs" Inherits="WebApplication1.WebForm13" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            var cb = new ComboBox
                            {
                              
                                ID = "cb",
                                AllowBlank = true,
                                FieldLabel = "test"
                            };
    
            Dictionary<int, string> items = new Dictionary<int, string>();
            items.Add(1, "test1");
            items.Add(2, "test2");
            items.Add(3, "test3");
    
            JsonReader jr = new JsonReader() { IDProperty = "Key" };
            jr.Fields.Add("Key", RecordFieldType.Int);
            jr.Fields.Add("Value", RecordFieldType.String);
    
            Store s = new Store();
            s.Reader.Add(jr);
            cb.Store.Add(s);
            
            s.DataSource = items;
            s.DataBind();
    
            cb.SelectedItem.Value = "2";
            
            Window1.Items.Add(cb);
            Window1.Render();
        }
    </script>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            <ext:Window ID="Window1" runat="server" Collapsible="true" Height="185" Icon="Application" Padding="20" Title="Title" Width="350" />
    </body>
    </html>
    thanks in advance!
    Last edited by Daniil; Jul 13, 2012 at 7:21 PM. Reason: [CLOSED]
  2. #2
    Hi,

    The DataSource can't accept a Dictionary object, please bind an array, list or DataTable.

    You also might need to set up the DisplayField and ValueField items for the ComboBox.
    http://docs.sencha.com/ext-js/3-4/#!/api/Ext.form.ComboBox-cfg-displayField
    http://docs.sencha.com/ext-js/3-4/#!/api/Ext.form.ComboBox-cfg-valueField

    Or just populate the Items collection.

    Also please remove
    Window1.Render();
    The Render method should be used during DirectEvent/DirectMethod only.
  3. #3
    that fixed it, thank you very much!
  4. #4
    var cb = new ComboBox
    {
        ID = "cb",
        AllowBlank = true,
        FieldLabel = "test",
        DisplayField = "Value",
        ValueField = "Key"
    };
    At Line Number 33

    Window1.Render(this.Form);

Similar Threads

  1. Replies: 8
    Last Post: Mar 15, 2012, 12:06 PM
  2. [CLOSED] Creating and Show ext.Window in CodeBehind
    By supera in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 08, 2012, 3:31 PM
  3. [CLOSED] Creating DirectEvent from codebehind
    By krzak in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 01, 2011, 10:17 AM
  4. Creating a Store From CodeBehind
    By ahmetmeral in forum 1.x Help
    Replies: 5
    Last Post: Dec 14, 2008, 5:14 PM
  5. Creating a delux portal from codebehind.
    By prashobkumar in forum 1.x Help
    Replies: 1
    Last Post: Dec 09, 2008, 11:36 AM

Posting Permissions