Ext的小问题,--------【标题内容太短!】 怎么样利用ExtJS把数据库的数据取出来再动态绑定到前台的下拉列表。有实例和核心代码最好。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //前台部分<html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title></title> <script type="text/javascript" src="../adapter/ext/ext-base.js"></script> <script type="text/javascript" src="../ext-all.js"></script> <link rel="stylesheet" type="text/css" href="../resources/css/ext-all.css"/></head><body> <form id="frm" runat="server"> <div id="AreaComboBox" style="margin-left:100px; margin-top:100px"></div> <script type="text/javascript" language="javascript"> function ready() { var store =new Ext.data.Store( { proxy: new Ext.data.HttpProxy({ method: 'GET', url: 'comboJson.aspx?Flag=1', params: { foo: 'bar'} }), reader: new Ext.data.JsonReader({ totalProperty: "totalProperty", root: "result", fields: [{ name: "PID" }, { name: "username"}] }) }); store.load(); var comboBox = new Ext.form.ComboBox( { id: "ComboBox_ID", store: store, triggerAction: 'all', valueField: 'PID', displayField: 'username', renderTo: 'AreaComboBox', resizable: true }); } Ext.onReady(ready); </script> </form></body></html>//comboJson.aspx文件中前台的部分(也就是说comboJson.aspx文件中前台部分html内容全删除了,只剩下以下内容)<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="comboJson.aspx.cs" Inherits="ExtJS.comboJson" %>//comboJson.aspx文件中后台的部分protected void Page_Load(object sender, EventArgs e){ string flag = Request.QueryString["Flag"]; switch (flag) { case "1": loadCombo("select top 10 PID,username from c_user" ); break; default: break; } } private void loadCombo( string strSql){ System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection("Data Source=192.168.1.4;Initial Catalog=PWMIS;User ID=sa;Password=zodiac"); try { System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter( strSql , con); con.Open(); DataTable dt = new DataTable(); da.Fill(dt); con.Close(); string json = ""; if (dt != null && dt.Rows.Count > 0) { json += "["; foreach (DataRow row in dt.Rows) { if (json != "[") json += ","; string tmp = "{"; foreach (DataColumn col in dt.Columns) { if (tmp != "{") tmp += ","; tmp += string.Format("\"{0}\":\"{1}\"", col.ColumnName, row[col.ColumnName].ToString()); } tmp += "}"; json += tmp; } json += "]"; json = "{totalProperty:10,result:" + json + "}"; } else { json = "错误"; } Response.Write(json); } catch (Exception e) { con.Close(); throw new Exception(e.Message); } } 用异常拦截来替代逻辑判断在性能方面影响大么?原因 报表绑定不上DataSet数据源 看别人的代码,学自己的习! 怎么在菜单项前加图标?! 关于还原数据库的问题 请问C#如何向xml文件中添加原素?? 有什么方法在操作其他东西的时候也能够拷屏 winForm中怎么得到选择的是datagrid的第几行啊? SOS:找不到文件或程序集名称“System”,或找不到它的一个依赖项。 怎么读取xls文件到listView 让一个窗体在这个程序的所有窗体的上面 【求助】问几个C#开发音频的问题
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<script type="text/javascript" src="../adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../ext-all.js"></script>
<link rel="stylesheet" type="text/css" href="../resources/css/ext-all.css"/>
</head>
<body>
<form id="frm" runat="server">
<div id="AreaComboBox" style="margin-left:100px; margin-top:100px"></div>
<script type="text/javascript" language="javascript">
function ready() {
var store =new Ext.data.Store(
{
proxy: new Ext.data.HttpProxy({ method: 'GET', url: 'comboJson.aspx?Flag=1', params: { foo: 'bar'} }),
reader: new Ext.data.JsonReader({ totalProperty: "totalProperty", root: "result", fields: [{ name: "PID" }, { name: "username"}] })
});
store.load();
var comboBox = new Ext.form.ComboBox(
{
id: "ComboBox_ID",
store: store,
triggerAction: 'all',
valueField: 'PID',
displayField: 'username',
renderTo: 'AreaComboBox',
resizable: true
});
}
Ext.onReady(ready);
</script>
</form>
</body>
</html>//comboJson.aspx文件中前台的部分(也就是说comboJson.aspx文件中前台部分html内容全删除了,只剩下以下内容)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="comboJson.aspx.cs" Inherits="ExtJS.comboJson" %>//comboJson.aspx文件中后台的部分
protected void Page_Load(object sender, EventArgs e)
{
string flag = Request.QueryString["Flag"];
switch (flag)
{
case "1":
loadCombo("select top 10 PID,username from c_user" );
break;
default:
break;
}
}
private void loadCombo( string strSql)
{
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection("Data Source=192.168.1.4;Initial Catalog=PWMIS;User ID=sa;Password=zodiac");
try
{
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter( strSql , con);
con.Open();
DataTable dt = new DataTable();
da.Fill(dt);
con.Close();
string json = "";
if (dt != null && dt.Rows.Count > 0)
{
json += "["; foreach (DataRow row in dt.Rows)
{
if (json != "[")
json += ","; string tmp = "{";
foreach (DataColumn col in dt.Columns)
{
if (tmp != "{")
tmp += ",";
tmp += string.Format("\"{0}\":\"{1}\"", col.ColumnName, row[col.ColumnName].ToString());
}
tmp += "}"; json += tmp;
} json += "]";
json = "{totalProperty:10,result:" + json + "}";
}
else
{
json = "错误";
}
Response.Write(json);
}
catch (Exception e)
{
con.Close();
throw new Exception(e.Message);
}
}