EXT.NET Динамически созданный ComboBox и Store

Я использую Ext.Net 1.3 с ASP.NET 4.0
Я хотел бы использовать C # динамически генерируемый ComboBox и Store, следующий мой код.

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);

Если вы не привязываете Store, на странице появится ComboBox. Если магазин привязан, ничего отображаться не будет. И браузер выдает сообщение об ошибке. введите сюда описание изображения Как решить эту проблему?


person vincent    schedule 04.05.2017    source источник


Ответы (1)


    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

person vincent    schedule 05.05.2017