• 后台生成json数据


     /// <summary>
            /// 生成JS按钮事件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void LBCreateAdFile_Click(object sender, EventArgs e)
            {
                string sMapPath = Server.MapPath("/Js/Date/HomeAd.js");
                string sTxt = string.Empty;
    
                string sql = " where State = 1 order by HomeAdvertisingId desc";
                IList<HomeAdvertisingInfo> hailists = HomeAdvertisingBLL.GetHomeAdvertisingByStr(sql);
                if (hailists.Count > 0)
                {
                    sTxt = "var HomeAdObj = [";
                    for (int i = 0; i < hailists.Count; i++)
                    {
                        sTxt += "{"Label":" + """ + hailists[i].Label + """ + ","ImgUrl":" + """ + hailists[i].ImgUrl + """ + ","BackgroundColor":" + """ + hailists[i].BackgroundColor + """ + ","Link":" + """ + hailists[i].Link + """ + ","State":" + """ + hailists[i].State + """ + ","Sort":" + """ + hailists[i].Sort + """ + "}";
                        if (hailists.Count > 1 && i < hailists.Count - 1)
                        {
                            sTxt += ",";
                        }
                    }
                    sTxt += "];";
                    File.WriteAllText(sMapPath, sTxt);
                    MessageBox.Show(this.Page, "生成文件成功");
                }
                else
                {
                    MessageBox.Show(this.Page, "暂无数据");
                }
                BindData();
            }
    

      

  • 相关阅读:
    安卓AlertDialog的使用
    蚂蚁的腿
    年龄排序
    Digital Roots
    小明的存钱计划
    不高兴的小明
    管闲事的小明
    小明的调查作业
    爱摘苹果的小明
    小明的难题
  • 原文地址:https://www.cnblogs.com/nik2011/p/3225726.html
Copyright © 2020-2023  润新知