qq_34422288 2016-06-17 00:59 采纳率: 0%
浏览 1032

easyui 与asp查询数据库给datagrid没有值是为什么?

  <a href="#" id="search" onclick="select()" data-options="toggle:true" onCls="icon-search">查找</a>
         <table id="showTable" onclick="showTable()"style="width:500px;padding:10px;"></table>
     <script type="text/javascript">
         function select()
         {
             $("#search").click(function () {
                 var queryParams = $('#showTable').datagrid('options').queryParams;
                 getQueryParams(queryParams);
                 $('#showTable').datagrid('options').queryParams = queryParams;
                 $("#showTable").datagrid('reload');
             })
         }
         function showTable() {
             $('#showTable').datagrid({
                 url: 'select.ashx',
                 pagination: true,
                 rownumbers: true,
                 singleSelect: true,
                 toolbar: '#toolDIV',
                 columns: [[
                 { field: 'DCode', title: 'DCode', width: 100, hidden: true },
                 { field: 'Ddivision', title: 'Ddivision', width: 100 },
                 { field: 'Dzl', title: 'Dzl', width: 100 },
                 { field: 'DTel', title: 'DTel', width: 100 },
                 { field: 'Dbz', title: 'Dbz', width: 100 }
                 ]]
             });
         } 
     </script>
    </div>
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int intPageSize = int.Parse(context.Request["rows"].ToString());
            int intCurrentPage = int.Parse(context.Request["page"].ToString());
            string name = context.Request["DCode"];
            string studentNo = context.Request["Ddivision"];
            string studentClass = context.Request["Dzl"];
            int total = StudentList(name, studentNo, studentClass).Count;
            var list = StudentList(name, studentNo, studentClass).Skip((intCurrentPage - 1) * intPageSize).Take(intPageSize);
            var studentJson = JsonConvert.SerializeObject(list);
            studentJson = TotalJson(studentJson, total);
            context.Response.Write(studentJson);
        }


        private string TotalJson(string rowJson, int total)
        {
            StringBuilder str = new StringBuilder();
            str.Append("{  \"total\":");
            str.Append(total);
            str.Append(",  \"rows\":");
            str.Append(rowJson);
            str.Append("}");
            return str.ToString();

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }


        //得到所有学生数据
        private DataTable GetStudentData()
        {
            string sql = "select *  from D_class";
            //MsDatabase db = new MsDatabase();
            return conn.QueryTable(sql);
        }
                 private List<Student> StudentList()
        {
            DataTable data = GetStudentData();
            List<Student> studentList = new List<Student>();
            foreach (DataRow row in data.Rows)
            {
                Student stu = new Student
                {
                    DTel = row["DTel"].ToString(),
                    DCode = Convert.ToInt32(row["DCode"]),
                    Dzl = row["Dzl"].ToString(),
                    Dbz = row["Dbz"].ToString(),
                    Ddivision = row["Ddivision"].ToString()
                };
                studentList.Add(stu);
            }
            return studentList;
        }
  • 写回答

2条回答

  • Go 旅城通票 2016-06-17 01:27
    关注

    你的datagrid在点击查询前初始化好没有,就是showTable要先于查询select执行,要不没有初始化就会报错,而且没看到你再哪里定义的getQueryParams函数,自己f12调出开发工具看报什么错

    评论

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R