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个回答

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

qq_34422288
qq_34422288 初学,不太懂,现在还很乱,能告诉具体咋改吗,十分感谢
大约 4 年之前 回复

这是我的select.ashx的内容
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().Count;
var list = StudentList().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;
    }
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐