0
votes

I am using Ext.Net 1.3 with ASP.NET 4.0
I would like to use C # dynamically generated ComboBox and Store, the following is my code.

var data = new object[]
        {
            new object[]{"AL", "Alabama", "The Heart of Dixie"},
            new object[] { "AK", "Alaska", "The Land of the Midnight Sun"},
            new object[] { "AZ", "Arizona", "The Grand Canyon State"},
            new object[] { "AR", "Arkansas", "The Natural State"},
            new object[] { "CA", "California", "The Golden State"},
            new object[] { "CO", "Colorado", "The Mountain State"},
            new object[] { "CT", "Connecticut", "The Constitution State"}
        };
 Ext.Net.ComboBox cmb = new Ext.Net.ComboBox();
            cmb.TypeAhead = true;
            cmb.ForceSelection = true;
            cmb.DisplayField = "ItemCode";
            cmb.ValueField = "ItemName";
            cmb.MinChars = 1;
            cmb.ListWidth = 400;
            cmb.PageSize = 10;
            cmb.ItemSelector = "tr.list-item";
            Store s = new Store();
            s.AddField(new RecordField() { Name = "ItemCode", Type = RecordFieldType.String }, 0);
            s.AddField(new RecordField() { Name = "ItemName", Type = RecordFieldType.String }, 1);
            s.AddField(new RecordField() { Name = "OnHand", Type = RecordFieldType.String }, 2);



            s.SaveAllFields = true;
            s.DataSource = data;
            s.DataBind();
            cmb.Store.Add(s); 


            StringBuilder sHtml = new StringBuilder();
            sHtml.Append(" <tpl for=\".\"><tpl if=\"[xindex] == 1\">");
            sHtml.Append("<table class=\"cbStates-list\" ><tr>");
            sHtml.Append("<th style=\"color: #2f353b !important;\">ItemCode</th>");
            sHtml.Append(" <th style=\"color: #2f353b !important;\">ItemName</th>");
            sHtml.Append("<th style=\"color: #2f353b !important;\">OnHand</th>");
            sHtml.Append("</tr> </tpl>");
            sHtml.Append("<tr class=\"list-item\">");
            sHtml.Append("<td style=\"padding:3px 0px;\">{ItemCode}</td>");
            sHtml.Append("<td>{ItemName}</td>");
            sHtml.Append("<td>{OnHand}</td>");
            sHtml.Append("</tr> <tpl if=\"[xcount-xindex]==0\">");
            sHtml.Append(" </table> </tpl> </tpl>");
            cmb.Template.Html = sHtml.ToString(); 
            Panel1.Items.Add(cmb);

If you do not bind the Store, the ComboBox will appear on the page. If the Store is bound, nothing will be displayed. And the browser gives an error message. enter image description here How to solve this problem?

1

1 Answers

0
votes
    HttpProxy proxy = new HttpProxy
                {
                    Method = HttpMethod.POST,
                    Url = "../../../Handlers/BoneWL.ashx"
                };

                        // Create Reader
                        Ext.Net.JsonReader reader = new Ext.Net.JsonReader
                        {
                            Root = "plants",
                            TotalProperty = "total",
                            Fields = {
                    new RecordField("ItemCode"),
                    new RecordField("ItemName"),
                    new RecordField("OnHand") 
                }
                        };

                        // Add Proxy and Reader to Store
                        Store store = new Store
                        {
                            Proxy = { proxy },
                            Reader = { reader },
                            AutoLoad = false
                        };

                        // Create ComboBox
                        Ext.Net.ComboBox cmb = new Ext.Net.ComboBox
                        {
                            DisplayField = "ItemCode",
                            ValueField = "ItemCode",
                            TypeAhead = false,
                            LoadingText = "加载中...",
                            Width = 240,
                            PageSize = 10,
                            HideTrigger = true,
                            ItemSelector = "tr.list-item",
                            MinChars = 1,
                            Store = { store }
                        };

                        cmb.Listeners.TriggerClick.Handler = "UseDirectEvents('1');WinRowCancelEdit();";
                        cmb.Triggers.Add(new FieldTrigger() { Icon = TriggerIcon.Search });
                        cmb.TriggerIcon = TriggerIcon.Search;
                        StringBuilder sHtml = new StringBuilder();
                        sHtml.Append(" <tpl for=\".\"><tpl if=\"[xindex] == 1\">");
                        sHtml.Append("<table class=\"cbStates-list\" ><tr>");
                        sHtml.Append("<th style=\"color: #2f353b !important;\">ItemCode</th>");
                        sHtml.Append(" <th style=\"color: #2f353b !important;\">ItemName</th>");
                        sHtml.Append("<th style=\"color: #2f353b !important;\">OnHand</th>");
                        sHtml.Append("</tr> </tpl>");
                        sHtml.Append("<tr class=\"list-item\">");
                        sHtml.Append("<td style=\"padding:3px 0px;\">{ItemCode}</td>");
                        sHtml.Append("<td>{ItemName}</td>");
                        sHtml.Append("<td>{OnHand}</td>");
                        sHtml.Append("</tr> <tpl if=\"[xcount-xindex]==0\">");
                        sHtml.Append(" </table> </tpl> </tpl>");
                        cmb.Template.Html = sHtml.ToString();
Panel1.Items.Add(cmb);

Example.portal