qileilove

blog已经转移至github,大家请访问 http://qaseven.github.io/

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 阅读(390) 评论(0)  编辑  收藏 所属分类: 测试学习专栏


只有注册用户登录后才能发表评论。


网站导航:
 
<2014年11月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

导航

统计

常用链接

留言簿(55)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜