Ext.net中ComboBox如何綁定數(shù)據(jù)庫(kù)中的值
今天在項(xiàng)目中再次碰到了問(wèn)題,就是Combobox中的值如果是直接綁定很簡(jiǎn)單。簡(jiǎn)單添加項(xiàng)就行了。代碼如下:
<ext:ComboBox ID="ComBox_SecretsLevel" runat="server" FieldLabel="密級(jí)" Width="250" EmptyText="請(qǐng)選擇密級(jí)..." > <Items> <ext:ListItem Text="公開(kāi)" Value="1"/> <ext:ListItem Text="保密" Value="2" /> <ext:ListItem Text="絕密" Value="3" /> </Items> </ext:ComboBox> |
但是要從數(shù)據(jù)庫(kù)中獲取綁定該如何操作呢?
找了下網(wǎng)上的質(zhì)量好像挺少的,去官網(wǎng)找了些Combobox的例子。雖然不是寫(xiě)死在控件上,但是發(fā)現(xiàn)他也只不過(guò)是通過(guò)獲取后臺(tái)的數(shù)組,然后綁定數(shù)據(jù)來(lái)操作的,也沒(méi)有真正的操作數(shù)據(jù)庫(kù)。于是我通過(guò)嘗試,結(jié)合了例子和實(shí)際,實(shí)現(xiàn)了綁定后臺(tái)數(shù)據(jù)庫(kù)的要求,這邊與大家分享下。
這邊數(shù)據(jù)庫(kù)中的參數(shù)及值如圖:
獲取表中數(shù)據(jù)只要簡(jiǎn)單的sql查詢(xún)語(yǔ)句,這邊就不詳細(xì)講解了。
在頁(yè)面中,首先是aspx頁(yè)面的代碼:
<%@ 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后臺(tái)數(shù)據(jù)</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="密級(jí)" Width="250" EmptyText="請(qǐng)選擇密級(jí)..." StoreID="Store_SecretsCom" ValueField="SecretsLevelID" DisplayField="SecretsLevelName"> </ext:ComboBox> </form> </body> </html> |
posted on 2014-11-17 10:38 順其自然EVO 閱讀(400) 評(píng)論(0) 編輯 收藏 所屬分類(lèi): 測(cè)試學(xué)習(xí)專(zhuān)欄