Extjs的combobox使用jsonstore获取asp.net后台数据

shixixi1987 2010-03-24 11:06:25
js源码
<!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>
<title>更多Extjs表单项</title>
<link rel="Stylesheet" type="text/css" href="Resources/CSS/ext-all.css" />
<script type="text/javascript" src="Extjs/ext-base-debug.js"></script>
<script type="text/javascript" src="Extjs/ext-all-debug.js"></script>
<script type="text/javascript" src="Extjs/ext-lang-zh_CN.js"></script>
<script type="text/javascript">
Ext.onReady(function() {
Ext.BLANK_IMAGE_URL = "Resources/Images/default/s.gif";

/*

var dstore = new Ext.data.JsonStore({
url: "getDepartment.aspx",
fields: ["Name", "Code"],
root: 'rows'
});
dstore.load();


var dateSelect = new Ext.form.FormPanel({
title: "日期选择",
labelSeparator: ':',
labelWidth: 60,
labelAlign: "right",
width: 600,
applyTo: 'dateSelect',
items: [
new Ext.form.DateField({
id: 'dfSelect',
format: 'Y年m月d日',
minValue: '1900-01-01',
maxValue: '3000-01-01',
disabledDaysText: '禁止选择该日期',
fieldLabel: '选择日期',
width: 150,
showToday: true
}),

new Ext.form.ComboBox({
id: "cbDepartment",
fieldLabel: "部门",
triggerAction: "all",
store: dstore,
valueField: "Code",
displayField: "Name",
mode: "local",
forceSection: true,
typeAhead: true,
resizeAble: true
}),

new Ext.form.HtmlEditor({
id: 'htmlContent',
width: 500,
autoHeight: false,
fieldLabel: "HTML编辑"
})
]
});
Ext.MessageBox.alert("Test the return record num", "共获得" + dstore.getCount() + "条数据");

});
</script>
</head>
<body>
<div id="dateSelect"></div>
</body>
</html>

asp.net页面源码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web
{
public partial class getDepartment : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string result = null;
result = "{rows:[{'Name':'开发部', 'Code':'1'}, {'Name':'销售部', 'Code':'2'}, {'Name':'行政部', 'Code':'3'}, {'Name':'质检部', 'Code':'4'}]}";
HttpContext.Current.Response.ContentType = "text/plain";
HttpContext.Current.Response.Write(result);
// Response.Write(result);
}
}
}
下拉框得不到数据,请问这段代码哪里有错误?
...全文
693 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
Style123111 2011-01-09
  • 打赏
  • 举报
回复
我也遇到了数据无法显示到Combox中的情况,请问楼主解决了吗,能否告知一下具体的解决方法~谢谢了~~
asdujiayong 2010-03-25
  • 打赏
  • 举报
回复
返回的应当是json格式的而不是string 类型的
kc8886 2010-03-24
  • 打赏
  • 举报
回复
这就是了 不是js的问题 是你后台的问题 首先 getDepartment.aspx 这个地址是不是你要请求的那个地址 我不懂.net 不知道这句话HttpContext.Current.Response.Write(result);
是否可以把字符串输出到页面
shixixi1987 2010-03-24
  • 打赏
  • 举报
回复
没有数据返回
kc8886 2010-03-24
  • 打赏
  • 举报
回复
代码应该没有问题 确定store里面有数据吗?
加这句试试看有没有数据返回
dstore.load({callback:function(){
alert("Test the return record num", "共获得" + dstore.getCount() + "条数据");
}});
lin364653705 2010-03-24
  • 打赏
  • 举报
回复
 if (!IsPostBack)
{
string result = null;
result = "{rows:[{'Name':'开发部', 'Code':'1'}, {'Name':'销售部', 'Code':'2'}, {'Name':'行政部', 'Code':'3'}, {'Name':'质检部', 'Code':'4'}]}";
}


http://www.cnblogs.com/Guzenyin/archive/2008/11/08/1329610.html这里去看下吧!
kc8886 2010-03-24
  • 打赏
  • 举报
回复
没错 .net 里是这样输出到页面的
Response.Write("{success:'false',msg:'增加人员失败!'}");
这样应该没错
Response.Write(result);
kc8886 2010-03-24
  • 打赏
  • 举报
回复
Response.Write(result);
试试 这个俺就无能为力了 .net俺不会
shixixi1987 2010-03-24
  • 打赏
  • 举报
回复
各位:我想请问一下如何使用EXTjs3.1中的jsonstore获取到asp.net服务器端的数据并在combobox中显示出来。我自己反反复复测试好多遍都不行,调试时,url所指定的页面有被调用,可就是没结果。js源码与asp.net页面源码如下,请各位高手指点!谢谢!
js源码
<!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>
<title>更多Extjs表单项</title>
<link rel="Stylesheet" type="text/css" href="Resources/CSS/ext-all.css" />
<script type="text/javascript" src="Extjs/ext-base-debug.js"></script>
<script type="text/javascript" src="Extjs/ext-all-debug.js"></script>
<script type="text/javascript" src="Extjs/ext-lang-zh_CN.js"></script>
<script type="text/javascript">
Ext.onReady(function() {
Ext.BLANK_IMAGE_URL = "Resources/Images/default/s.gif";

/*

var dstore = new Ext.data.JsonStore({
url: "getDepartment.aspx",
fields: ["Name", "Code"],
root: 'rows'
});
dstore.load();


var dateSelect = new Ext.form.FormPanel({
title: "日期选择",
labelSeparator: ':',
labelWidth: 60,
labelAlign: "right",
width: 600,
applyTo: 'dateSelect',
items: [
new Ext.form.DateField({
id: 'dfSelect',
format: 'Y年m月d日',
minValue: '1900-01-01',
maxValue: '3000-01-01',
disabledDaysText: '禁止选择该日期',
fieldLabel: '选择日期',
width: 150,
showToday: true
}),

new Ext.form.ComboBox({
id: "cbDepartment",
fieldLabel: "部门",
triggerAction: "all",
store: dstore,
valueField: "Code",
displayField: "Name",
mode: "local",
forceSection: true,
typeAhead: true,
resizeAble: true
}),

new Ext.form.HtmlEditor({
id: 'htmlContent',
width: 500,
autoHeight: false,
fieldLabel: "HTML编辑"
})
]
});
Ext.MessageBox.alert("Test the return record num", "共获得" + dstore.getCount() + "条数据");

});
</script>
</head>
<body>
<div id="dateSelect"></div>
</body>
</html>

asp.net页面源码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web
{
public partial class getDepartment : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string result = null;
result = "{rows:[{'Name':'开发部', 'Code':'1'}, {'Name':'销售部', 'Code':'2'}, {'Name':'行政部', 'Code':'3'}, {'Name':'质检部', 'Code':'4'}]}";
HttpContext.Current.Response.ContentType = "text/plain";
HttpContext.Current.Response.Write(result);
// Response.Write(result);
}
}
}
shixixi1987 2010-03-24
  • 打赏
  • 举报
回复
不能输出

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧