2017-05-04 14 views
0

ASP.NET 4.0でExt.Net 1.3を使用しています
私は動的に生成されたComboBoxとStoreを使用したいと思います。以下は私のコードです。EXT.NET動的に作成されたコンボボックスとストア

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

ストアをバインドしないと、コンボボックスがページに表示されます。 ストアがバインドされている場合、何も表示されません。ブラウザはエラーメッセージを表示します。 enter image description here この問題を解決するにはどうすればよいですか?

答えて

0
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

関連する問題