Ext.net中ComboBox如何綁定數據庫中的值
今天在項目中再次碰到了問題,就是Combobox中的值如果是直接綁定很簡單。簡單添加項就行了。代碼如下:
<ext:ComboBox ID="ComBox_SecretsLevel" runat="server" FieldLabel="密級" Width="250" EmptyText="請選擇密級..." > <Items> <ext:ListItem Text="公開" Value="1"/> <ext:ListItem Text="保密" Value="2" /> <ext:ListItem Text="絕密" Value="3" /> </Items> </ext:ComboBox> |
但是要從數據庫中獲取綁定該如何操作呢?
找了下網上的質量好像挺少的,去官網找了些Combobox的例子。雖然不是寫死在控件上,但是發現他也只不過是通過獲取后臺的數組,然后綁定數據來操作的,也沒有真正的操作數據庫。于是我通過嘗試,結合了例子和實際,實現了綁定后臺數據庫的要求,這邊與大家分享下。
這邊數據庫中的參數及值如圖:
獲取表中數據只要簡單的sql查詢語句,這邊就不詳細講解了。
在頁面中,首先是aspx頁面的代碼:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LR_FileReg.aspx.cs" Inherits="EasyCreate.DFMS.WebUI.LR_FileReg" %> <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>綁定Combobox后臺數據</title> </head> <body> <form id="form1" runat="server"> <ext:ResourceManager ID="ResourceManager1" runat="server"/> <ext:Store ID="Store_SecretsCom" runat="server"> <Reader> <ext:JsonReader> <Fields> <ext:RecordField Name="SecretsLevelID" Type="Int"/> <ext:RecordField Name="SecretsLevelName" Type="String" /> </Fields> </ext:JsonReader> </Reader> </ext:Store> <ext:ComboBox ID="ComBox_SecretsLevel" runat="server" FieldLabel="密級" Width="250" EmptyText="請選擇密級..." StoreID="Store_SecretsCom" ValueField="SecretsLevelID" DisplayField="SecretsLevelName"> </ext:ComboBox> </form> </body> </html> |
posted on 2014-11-17 10:38 順其自然EVO 閱讀(400) 評論(0) 編輯 收藏 所屬分類: 測試學習專欄