May 28, 2010, 8:45 AM
Binding ComboBox
Hi,
I am filling a ComboBox as follows:
<script type="text/javascript">
var dataLoaded = function (store, records) {
if (records.length > 0)
DetailsForm.form.loadRecord(records[0]);
else
DetailsForm.form.reset();
}
</script>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
this.Store1.DataBind();
this.Store2.DataSource = new List<object>
{
new {Id = 0, Name = "Name 0"},
new {Id = 1, Name = "Name 1"},
new {Id = 2, Name = "Name 2"},
};
this.Store2.DataBind();
}
</script>
<ext:Store ID="Store1" runat="server" DataSource="<%# Model.ToList() %>">
<Reader>
<ext:JsonReader IDProperty="KEY" MessageProperty="message">
<Fields>
<ext:RecordField Name="ID" SortDir="ASC"/>
<ext:RecordField Name="NAME" />
<ext:RecordField Name="DESC" />
<ext:RecordField Name="TYPE" Type="int" />
</Fields>
</ext:JsonReader>
</Reader>
<SortInfo Field="ID" Direction="ASC" />
<Listeners>
<Load Fn="dataLoaded" />
</Listeners>
</ext:Store>
<ext:Store ID="Store2" runat="server">
<Reader>
<ext:JsonReader>
<Fields>
<ext:RecordField Name="Id" />
<ext:RecordField Name="Name" />
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
<ext:FormPanel ID="DetailsForm" runat="server" Url="/Test/Save/" Border="false">
<Items>
<ext:ComboBox
ID="TYPE"
runat="server"
StoreID="Store2"
Editable="false"
DisplayField="Name"
ValueField="Id"
TypeAhead="true"
FieldLabel="Type"
ForceSelection="true"
ItemCls="required"
Width="100">
</ext:ComboBox>
</Items>
</ext:FormPanel>
ComboBox is loading data without any problem, but although the correct value is selected, the combo displays the integer TYPE as text.How can I select and display the correct value field?