1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2"%>
2
3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5 <html xmlns="http://www.w3.org/1999/xhtml">
6 <head runat="server">
7 <title>无标题页</title>
8 <script type="text/javascript" src="JS/jquery-1.4.1-vsdoc.js"></script>
9 <script type="text/javascript" src="flexigrid-1.1/js/flexigrid.js"></script>
10 <link href="flexigrid-1.1/css/flexigrid.css" type="text/css" rel="stylesheet"/>
11 <link href="flexigrid-1.1/css/flexigrid.pack.css" type="text/css"/>
12 <script type="text/javascript">
13 <%--
14 $(document).ready(function() {
15 $("#grdProList").flexigrid(
16 {
17 url: "Default3.aspx?id=test",//这样写好像无法获得数据,请高人指点
18 dataType: 'json',
19 colModel: [
20 // { display: '<input type="checkbox" id="checkAll"/>', name: 'check', width: 50, sortable: false, align: 'center', hide: false },
21 //{display: '选择', name: '', sortable: true, width: 20, align: 'center' },
22 { display: '项目编码', name: 'pro_no', sortable: true, width: 80, align: 'center' },
23 { display: '项目名称', name: 'pro_name', sortable: true, width: 80, align: 'center' },
24 { display: '业务类别', name: 'pro_type', sortable: true, width: 80, align: 'left' },
25 { display: '业务类别2', name: 'pro_type2', sortable: true, width: 80, align: 'left' },
26 { display: '投资规模', name: 'pro_invest', sortable: true, width: 80, align: 'left' }
27 ],
28 buttons: [
29 { name: '显示 / 隐藏查询',
30 bclass: 'showMagnifier'//,
31 //onpress: queryBt
32 },
33 {
34 name: '导出excel',
35 bclass: 'showMagnifier'//,
36 //onpress: toExcel
37 }
38 ],
39 searchitems: [
40 { display: '项目编码', name: 'pro_no' },
41 { display: '项目名称', name: 'pro_name' },
42 { display: '业务类别', name: 'pro_type' }
43 ],
44
45 ShowToggleCol: true,
46 singleSelect: true,
47 sortname: 'pro_no',
48 sortorder: 'asc',
49 usepager: true,
50 striped: true,
51 title: '项目列表',
52 useRp: true,
53 rp: 20,
54 width: 860,
55 // hideOnSubmit: true,
56 // onSubmit: addFormData,
57 height: 400,
58 //pagestat: '显示 {from} 到 {to}, 共 {total} 条',
59 procmsg: '请等待数据正在加载中 …',
60 nomsg: '没有数据',
61 onError: '查询出错,请刷新'
62 });
63
64 function queryBt() {
65 // $("#sform").slideToggle(200);
66 }
67 function toExcel() {
68 preview();
69
70 }
71
72 });--%>
73 </script>
74 </head>
75 <body>
76 <form id="form1" runat="server">
77 <table id="grdProList" style="display: none;">
78
79 </table>
80 </form>
81 </body>
82 </html>
后台数据源(Default3.aspx.cs)
public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string index = Request.QueryString["id"];
if (index == "test")
{
getjson();
}
}
public void getjson()
{
Response.ContentType = "application/json";
StringBuilder json = new StringBuilder();
json.Append("{");
json.Append("page: 1,");
json.Append("total: 1,");
json.Append("rows: [");
//json.Append(",");
//first row
json.Append("{");
json.Append("id:'row1',");
json.Append("cell:['iso'");
json.Append(",'name'");
json.Append(",'printable_name'");
json.Append(",'iso3'");
json.Append(",'numcode']");
json.Append("},");
//second row
json.Append("{");
json.Append("id:'row2',");
json.Append("cell:['iso-2'");
json.Append(",'name-2'");
json.Append(",'printable_name-2'");
json.Append(",'iso3-2'");
json.Append(",'numcode-2']");
json.Append("}");
json.Append("]");
json.Append("}");
Response.Write(json);
}
}
以上为所有的代码,就是不能在前台页面显示数据,请高手帮忙看看!!
说明:
如果数据源是从 *.ashx这样的文件获得就没有问题。现在就想从*aspx.cs中获得数据
开头使用Respose.Clear()
结束处使用Response.End();
如果实在不行,使用FireBug或Fiddler看看传递的内容差别,一般都是返回的头信息有问题