public void ProcessRequest(HttpContext context)
{
string id = "BUDGET0001";// context.Request.Form["id"];//类型
DataTable ds = new DataTable();
DataTable dt = new DataTable();
string yuyu = "";
string sfile="";
string sfilevalue = "";
string mm = "";
dt = comm_data.gettablebypruce("qg_budget_code","", "qgid asc");
ds = comm_data.gettablebypruce("qg_data", "t.dataid='" + id + "'", "t.displaynum asc");
if (ds.Rows.Count != 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
yuyu = "{\"id\":\"" + dt.Rows[i]["qgid"].ToString() + "\",";
for (int k = 0; k < ds.Rows.Count; k++)
{
sfile=ds.Rows[k]["datafile"].ToString();
sfilevalue = dt.Rows[i][sfile].ToString();
if (sfile == "BUDGETPARENTCODE")
{
if (sfilevalue!="") {
yuyu = yuyu + "\"_parentId\":\"" + sfilevalue + "\",";
}
}
yuyu = yuyu + "\"" + sfile + "\":\"" + sfilevalue + "\",";
}
yuyu = yuyu.Substring(0, yuyu.Length - 1);
mm = mm + "," + yuyu + "}";
}
mm = mm.Remove(0, 1);
mm = "{\"total\":\"88888\",\"rows\":[" + mm + "]}";
}
context.Response.Write(mm);
}
格式为:{“total":88,"rows":[ {"id":22,"name":"UML","persons":1,"begin":"3/7/2010","end":"3/8/2010","progress":100,"_parentId":2},{ },{ }]}
不面是结合数据库表data中已经设置好的数据字段及进行
<table id="dg"></table>
<script>
function formatPrice(val, row) {
var str="";
var cc=row.BUDGETCODE.length;
if ( cc> 1) {
for (var i = 1; i <cc; i++)
{ str = str + " " }
return str+ val;
} else {
return val;
}
}
function formartid(a)
{
var str;
if (a.length>1)
{
for(var i=1;i<a.length;i++)
str=str+" "
}
return str+a;
}
$('#dg').edatagrid({
url: '../ashprama/test01.ashx',
title: '11111',
fit: false,
columns: [[
{ field: 'QGID', title: 'ID', width: '30', hidden: 'true' },
{ field: 'BUDGETNAME', title: '类别', width: '200', formatter: formatPrice },
{ field: 'BUDGETCODE', title: '代码', width: '50' },
{ field: 'BUDGETPARENTCODE', title: '父类代码', width: '75', hidden: 'true' },
{ field: 'CONTRACTID', title: '合同编号', width: '204', editor: 'text' },
{ field: 'CONTRACTNAME', title: '合同名称', width: '120', editor: 'text' },
{ field: 'REMARK', title: '备注', width: '120', editor: 'text' },
{ field: 'COSTS', title: '成本 ', width: '120', editor: 'text' },
{ field: 'QMONEY', title: '资金', width: '70', editor: 'text' }
]]})
</script>