Coolite ComboBox数据绑定
aspx代码:
1 <div>
2 <ext:Store ID="Store1" runat="server" AutoLoad="true">
3 <Reader>
4 <ext:jsonreader readerid="employee_no">
5 <%--<ext:ArrayReader>--%>
6 <Fields>
7 <ext:RecordField Name="employee_no">
8 </ext:RecordField>
9 <ext:RecordField Name="employee_display_name">
10 </ext:RecordField>
11 </Fields>
12 <%--</ext:ArrayReader>--%>
13 </ext:JsonReader>
14 </Reader>
15 </ext:Store>
16 <ext:ComboBox ID="ComboBox1" runat="server" StoreID="Store1" Width="250" Editable="false"
17 TypeAhead="true" Mode="Local" ForceSelection="true" TriggerAction="All" SelectOnFocus="true"
18 EmptyText="Please choose..." >
19 </ext:ComboBox>
20 </div>
21 <ext:ScriptManager ID="ScriptManager1" runat="server">
22 </ext:ScriptManager>
CS代码:
1 foreach (DataRow r in ds.Tables[0].Rows)
2 {
3 ComboBox1.Items.Add(new Coolite.Ext.Web.ListItem(r[1].ToString(), r[0].ToString()));
4 }
用这种方式时,页面使用jsonreader或ArrayReader均可;
或者以下方式绑定:
cs代码:
1 Store1.DataSource = ds.Tables[0];
2 Store1.DataBind();
3 ComboBox1.ValueField = "employee_no";
4 ComboBox1.DisplayField = "employee_display_name";
5 //ComboBox1.StoreID = Store1.ClientID;
6 ComboBox1.DataBind();
用这种方式时,页面使用jsonreader;StoreID 如果页面指定,则此处可不加ComboBox1.StoreID = Store1.ClientID;