[英]Combo box display only blank list
我正在使用Ext.net 3.0。 我有一個組合框並在其中創建了存儲,以從服務器端獲取多個值。 它從服務器端獲取5值,但僅顯示空白列表。
組合框的編碼..............
<ext:ComboBox runat="server" ListWidth="350" ID="Branches" FieldLabel="Branch" DisplayField="Name" ValueField="Number" AllowBlank="false">
<Store>
<ext:Store runat="server">
<Reader>
<ext:JsonReader IDProperty="Number">
<Fields>
<ext:RecordField Name="Number"></ext:RecordField>
<ext:RecordField Name="Name"></ext:RecordField>
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
</Store>
</ext:ComboBox>
服務器端編碼.......
var branchList = from b in Branches select new { Number = b.Number, Name = b.Name };
List<object> listBranchToAdd = new List<object>();
foreach (var a in branchList)
{
listBranchToAdd.Add(a);
}
Branches.Store.Primary.DataSource = listBranchToAdd;
Branches.Store.Primary.DataBind();
我的研究-
有人說過,不要直接在商店中添加組合,不要通過給定商店ID單獨創建商店,然后在組合中使用商店ID,但這是行不通的。
var branchList返回值..我已經檢查了它。 當我使用cmbBranches.setValue(listBranchToAdd [0]); 然后在Fiddler中顯示值。 但無法正確顯示在組合框中。
3.只需在商店中提供一個storeId並在服務器端使用它來綁定商店中的數據,而不是在組合框中進行綁定。 我已經嘗試過了,但是沒有用。
看這個例子
<ext:ComboBox runat="server" ID="cmb" EmptyText="select.." ForceSelection="true" AllowBlank="false"
Editable="false" Icon="BulletTick" Flex="1" ValueField="Id" DisplayField="Name" FieldLabel="Name">
<Store>
<ext:Store ID="strcmb" runat="server">
<Model>
<ext:Model ID="Model4" runat="server">
<Fields>
<ext:ModelField Name="Number" />
<ext:ModelField Name="Name" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>
和服務器端
strcmb.DataSource = _bll.Get();
strcmb.DataBind();
在這種情況下,如果不提出Web服務請求,則不需要<Reader><ext:JsonReader...>
這部分
更新
var branchList = from b in Branches select new MyClass { Number = b.Number, Name = b.Name };
strcmb.DataSource = branchList.ToList();
strcmb.DataBind();
MyClass{
public string Name {get;set;}
public int Number {get ;set;}
}
最后,我得到了這個問題的解決方案。 我沒有正確理解為什么它起作用的實際邏輯,但是它正常工作。
先前的代碼-無法正常工作
var branchList = from b in Branches select new { Number = b.Number, Name = b.Name };
List<object> listBranchToAdd = new List<object>();
foreach (var a in branchList)
{
listBranchToAdd.Add(a);
}
Branches.Store.Primary.DataSource = listBranchToAdd;
Branches.Store.Primary.DataBind();
新代碼-正在運行
var branchList = from b in Branches select b;
List<Branch> listBranchToAdd = new List<Branch>();
foreach (var a in branchList)
{
listBranchToAdd.Add(a);
}
Branches.Store.Primary.DataSource = listBranchToAdd;
Branches.Store.Primary.DataBind();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.