private void GetJsonForDatagrid(HttpContext context)
        {
            int totalRecords = 0;
            int pageIndex    = 1;
            int pageSize     = 10;

            int.TryParse(context.Request.QueryString["page"], out pageIndex);
            int.TryParse(context.Request.QueryString["rows"], out pageSize);
            string       sqlWhere = string.Empty;
            SqlParameter parm     = null;

            if (!string.IsNullOrEmpty(context.Request.QueryString["companyName"]))
            {
                sqlWhere   = "and CompanyName like @CompanyName ";
                parm       = new SqlParameter("@CompanyName", SqlDbType.NVarChar, 50);
                parm.Value = "%" + context.Request.QueryString["companyName"].Trim() + "%";
            }

            PropertyCompany bll  = new PropertyCompany();
            var             list = bll.GetList(pageIndex, pageSize, out totalRecords, sqlWhere, parm);

            if (list == null || list.Count == 0)
            {
                context.Response.Write("{\"total\":0,\"rows\":[]}");
                return;
            }
            StringBuilder sb = new StringBuilder();

            foreach (var model in list)
            {
                sb.Append("{\"Id\":\"" + model.Id + "\",\"CompanyName\":\"" + model.CompanyName + "\",\"ShortName\":\"" + model.ShortName + "\",\"ProvinceCityId\":\"" + model.ProvinceCityId + "\",\"Province\":\"" + model.Province + "\",\"City\":\"" + model.City + "\",\"District\":\"" + model.District + "\"},");
            }
            context.Response.Write("{\"total\":" + totalRecords + ",\"rows\":[" + sb.ToString().Trim(',') + "]}");
        }
Example #2
0
        /// <summary>
        /// 获取数据分页列表,并返回所有记录数
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalRecords"></param>
        /// <param name="sqlWhere"></param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public string GetPropertyCompanyList(int pageIndex, int pageSize, out int totalRecords, string sqlWhere, params SqlParameter[] cmdParms)
        {
            PropertyCompany            bll  = new PropertyCompany();
            List <PropertyCompanyInfo> list = bll.GetList(pageIndex, pageSize, out totalRecords, sqlWhere, cmdParms);

            if (list == null || list.Count == 0)
            {
                return("[]");
            }
            return(JsonConvert.SerializeObject(list));
        }
Example #3
0
        /// <summary>
        /// 获取数据列表
        /// </summary>
        /// <returns></returns>
        public string GetPropertyCompanyList()
        {
            PropertyCompany            bll  = new PropertyCompany();
            List <PropertyCompanyInfo> list = bll.GetList();

            if (list == null || list.Count == 0)
            {
                return("[]");
            }
            return(JsonConvert.SerializeObject(list));
        }
Example #4
0
        /// <summary>
        /// 获取满足当前条件的数据列表
        /// </summary>
        /// <param name="sqlWhere"></param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public string GetPropertyCompanyList(string sqlWhere, params SqlParameter[] cmdParms)
        {
            PropertyCompany            bll  = new PropertyCompany();
            List <PropertyCompanyInfo> list = bll.GetList(sqlWhere, cmdParms);

            if (list == null || list.Count == 0)
            {
                return("[]");
            }
            return(JsonConvert.SerializeObject(list));
        }
        private void Bind()
        {
            //查询条件
            GetSearchItem();

            List <PropertyCompanyInfo> list = null;
            int totalRecords = 0;

            PropertyCompany bll = new PropertyCompany();

            if (parms != null && parms.Count() > 0)
            {
                list = bll.GetList(pageIndex, pageSize, out totalRecords, sqlWhere, parms == null ? null : parms.ToArray());
            }
            else
            {
                list = bll.GetList(pageIndex, pageSize, out totalRecords, "", null);
            }

            rpData.DataSource = list;
            rpData.DataBind();

            myDataAppend += "<div id=\"myDataForPage\" style=\"display:none;\">[{\"PageIndex\":\"" + pageIndex + "\",\"PageSize\":\"" + pageSize + "\",\"TotalRecord\":\"" + totalRecords + "\",\"QueryStr\":\"" + queryStr + "\"}]</div>";
        }