首页 新闻 赞助 找找看

easyui问题

0
悬赏园豆:5 [已解决问题] 解决于 2012-04-01 09:58

我在代码中把表数据转换成json了,

string newsJson = JsonConvert.SerializeObject(dt);

怎么输出到页面啊?

问题补充:

前台:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<link href="../JS/easyui/themes/default/easyui.css" rel="stylesheet" type="text/css" />
<link href="../JS/easyui/themes/icon.css" rel="stylesheet" type="text/css" />
<script src="../JS/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="../JS/easyui/jquery.easyui.min.js" type="text/javascript"></script>
<style type="text/css">
a{ text-decoration: none;}
</style>
<script type="text/javascript">
function bindJson() {
$('#news').datagrid({
url: 'DataTableToJson.aspx?action=bind',
title: '新闻列表',
width: 1024,
height: 300,
fitColumns: true,
nowrap: false,
idField: 'ID',
columns: [[
{ field: 'ID', title: '新闻编号', width: 100, align: 'center' },
{ field: 'Title', title: '新闻标题', width: 200, align: 'center' },
{ field: 'NewsContent', title: '新闻内容', width: 300, align: 'center'}
]]

});
};
</script>
</head>
<body onload="bindJson();">
<table id="news"></table>
</body>
</html>

 

 

后台;

public partial class DataTableToJson : JsonBase
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
switch (Action)
{
case "bind"://用户列表
Bind();
break;
}
}
}

public string Bind()
{
DataTable dt = BLLFuntions.GetDataSource(new tb_News());
string newsJson = JsonConvert.SerializeObject(dt); //转换为json的数据,
return newsJson;
//接下来怎么和 $('#news').datagrid挂钩
}
}

iisp的主页 iisp | 初学一级 | 园豆:81
提问于:2012-03-28 13:39
< >
分享
最佳答案
0

我认为楼主是不了解json吧。

json简介:http://zh.wikipedia.org/zh/JSON

遍历json:http://www.nowamagic.net/javascript/js_TraversalJson.php

用js动态创建页面元素:http://www.leadsir.com/?p=386

我感觉看完这些应该就可以解决你的问题了。

收获园豆:5
吕飞 | 菜鸟二级 |园豆:280 | 2012-03-28 14:19

求QQ或者邮件联系方式

iisp | 园豆:81 (初学一级) | 2012-03-28 15:47

@iisp: 

  1. 先确认下'DataTableToJson.aspx?action=bind的数据是否正确
  2. 查看下JQuery DataGrid 的文档 确认js调用是否出现问题。
JQuery DataGrid 这个插件我没有用过,没有使用经验,所以只能提供解决问题思路。
吕飞 | 园豆:280 (菜鸟二级) | 2012-03-28 17:44
其他回答(1)
0

如果后台是一般处理程序返回json是context.response.write(json);

aspx页的后台是response.write(json);

Hello World!!!!! | 园豆:270 (菜鸟二级) | 2014-06-21 21:44
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册