生成树(treegrid)的数据格式

    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>


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值