C# 返回一个JSON数据

前端

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="yujkc.aspx.cs" Inherits="NetWing.BPM.Admin.psi.yujkc" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data.Sql" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>预警产品</title>
    <script src="../scripts/jquery-1.10.2.min.js"></script>
    <link href="../../layUI/src/css/layui.css" rel="stylesheet" />
</head>
<body>
   <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">预警产品</div>
                    <div class="layui-card-body">
                        <table class="layui-hide" id="test-table-checkbox"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="../scripts/layui/layui.all.js"></script>
    <script>
        layui.use(['table'], function () {
            var table = layui.table;
            table.render({
                elem: '#test-table-checkbox'
                , cols: [[
                    { field: 'id', title: '序号', type: 'numbers' }
                    , { field: 'KeyId', title: 'ID', sort: true }
                    , { field: 'goodsNo', title: '商品编码' }
                    , { field: 'goodsName', title: '商品名称' }
                    , { field: 'goodsShortName', title: '商品简称' }
                    , { field: 'goodsClassName', title: '商品分类名称' }
                    , { field: 'specs', title: '规格' }
                    , { field: 'unit', title: '单位' }
                    , { field: 'buyPrice', title: '进价' }
                    , { field: 'up_time', title: '最后更新时间' }
                ]]
                , data: [<%=sDateJson%>]
            });
        });
    </script>


 
</body>
</html>

后台

using NetWing.Common.Data.SqlServer;
using System;
using System.Data;

namespace NetWing.BPM.Admin.psi
{
    public partial class yujkc : System.Web.UI.Page
    {
        protected string sDateJson;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) 
            {
                DateTime dtnow = DateTime.Now;
                DataTable dttable = SqlEasy.ExecuteDataTable("select * from Psi_Goods");
                foreach (DataRow dr in dttable.Rows)
                {
                    DateTime dttime = Convert.ToDateTime(dr["up_time"].ToString());
                    if (dtnow.AddMonths(-4) > dttime)
                    {
                        sDateJson += "{\"KeyId\":" + dr["KeyId"].ToString() + ",\"goodsNo\":\"" + dr["goodsNo"].ToString() + "\",\"goodsName\":\"" + dr["goodsName"].ToString() + "\",\"goodsShortName\":\"" + dr["goodsShortName"].ToString() + "\",\"goodsClassName\":\"" + dr["goodsClassName"].ToString() + "\",\"specs\":\"" + dr["specs"].ToString() + "\",\"unit\":\"" + dr["unit"].ToString() + "\",\"stock\":\"" + dr["stock"].ToString() + "\",\"buyPrice\":\"" + dr["buyPrice"].ToString() + "\",\"up_time\":\"" + dr["up_time"].ToString() + "\"},";
                    }
                    //if (!string.IsNullOrEmpty(sDateJson))
                    //{
                    //    sDateJson = sDateJson.Substring(0, sDateJson.Length - 1);
                    //}
                }
            }
        }
     
    }
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值