我使用Ajax请求使用一个服务填充Combobox商店值以使用以下代码自动显示匹配的文本(过滤)
<ext:ComboBox ID="cbManager" runat="server" DisplayField="FirstName"
LabelAlign="Right" ValueField="EmployeeID" AllowBlank="false"
HideTrigger="true" MinChars="1" FieldLabel="* Manager" >
<ext:Store ID="storeManager" runat="server" AutoLoad="false">
<Proxy>
<ext:AjaxProxy Url="~/Modules/eHRMS/FilterEmployeeNames.ashx?empType=1">
<ActionMethods Read="GET" />
<Reader>
<ext:JsonReader Root="employees" TotalProperty="total" />
</Reader>
</ext:AjaxProxy>
</Proxy>
<Model>
<ext:Model ID="Model4" runat="server">
<Fields>
<ext:ModelField Name="EmployeeID" />
<ext:ModelField Name="FirstName" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>
当我从Combobox中选择任何名称时,它会给出正确的 价值但是当我尝试使用代码填充ComboBox值时 仅显示未显示EmplyeeName的EmployeeID(Value)
我在CodeBehind中使用了以下代码
员工emp = GetProject(EmployeeID); cbManager.SetValue(project.ManagerID);
I have also tried the following one also
cbManager.Select(project.ManagerID.ToString());
但它只显示int值而不是String(即EmployeeName)
这种行为可能是什么原因,请建议我 正确的方式。
谢谢
答案 0 :(得分:1)
您应该添加与此值对应的记录,然后设置值:
<%@ Page Language="C#" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
Store store = this.ComboBox1.GetStore();
store.Data = new object[]
{
new
{
value = "2",
text = "Item 2"
}
};
}
}
protected void Store_OnReadData(object sender, StoreReadDataEventArgs e)
{
Store store = sender as Store;
store.DataSource = new object[]
{
new { value = "1", text = "Item 1" },
new { value = "2", text = "Item 2" },
new { value = "3", text = "Item 3" }
};
store.DataBind();
}
protected void ButtonClick(object sender, DirectEventArgs e)
{
ComboBox1.GetStore().Add(new object[]
{
new
{
value = "4",
text = "Item 4"
}
});
ComboBox1.SetValue("4");
}
</script>
<!DOCTYPE html>
<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:ComboBox
ID="ComboBox1"
runat="server"
DisplayField="text"
ValueField="value">
<Store>
<ext:Store runat="server" OnReadData="Store_OnReadData">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="value" />
<ext:ModelField Name="text" />
</Fields>
</ext:Model>
</Model>
<Proxy>
<ext:PageProxy>
<Reader>
<ext:JsonReader />
</Reader>
</ext:PageProxy>
</Proxy>
</ext:Store>
</Store>
<SelectedItems>
<ext:ListItem Index="0" />
</SelectedItems>
</ext:ComboBox>
<ext:Button runat="server" Text="Set some value">
<DirectEvents>
<Click OnEvent="ButtonClick"></Click>
</DirectEvents>
</ext:Button>
</form>
</body>
</html>