Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, iam using jqgrid using json result but grid is not populating plz help me
here is my code
for controller:
C#
public JsonResult GetEmployeeData()
        {
            List<models.empdetails> emp = new List<models.empdetails>();
            con.Open();
            string query = "select * from EmpDetail where StatusTypeId=1  order by EmpId DESC";
            SqlCommand cmd = new SqlCommand(query, con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            cmd.CommandType = CommandType.Text;
            DataSet ds = new DataSet();
            da.Fill(ds);
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                emp.Add(new Models.EmpDetails()
                {
                    Name = dr[0].ToString(),
                    EmpId = Convert.ToInt32(dr[1].ToString()),
                    Salary = Convert.ToInt32(dr[2].ToString()),
                    Address = dr[3].ToString(),
                    ZipCode = Convert.ToInt32(dr[4].ToString()),
                    PhoneNumber = Convert.ToInt32(dr[5].ToString()),
                    Permanent = Boolean.Parse(dr[7].ToString()),
                    Birthday = Convert.ToDateTime(dr[8].ToString()),
                    Country = dr[9].ToString()
                });
            }
            cmd.ExecuteNonQuery();
            return Json(emp, JsonRequestBehavior.AllowGet);
        }

jquery:
C#
$(document).ready(function () {
        $('#grd').jqGrid(
        {
            dataType: 'json',
            height: 250,
            mtype: 'Get',
            url: '/Home/GetEmployeeData',
            colNames: ['Name', 'Address', 'Salary', 'PhoneNumber', 'Zipcode', 'Permanent', 'Birthday', 'Country'],
            colModel: [{ name: 'Name', index: 'Name', width: 80 },
                       { name: 'Address', index: 'Address', width: 100 },
                       { name: 'Salary', index: 'Salary', width: 60 },
                       { name: 'PhoneNumber', index: 'PhoneNumber', width: 75 },
                       { name: 'ZipCode', index: 'ZipCode', width: 75 },
                       { name: 'Permanent', index: 'Permanent', width: 60 },
                       { name: 'Birthday', index: 'Birthday', width: 75 },
                       { name: 'Country', index: 'Country', width: 100 }

            ],
            cation: 'EmplyoeeDetails',
            pager: $('#pager'),
            sortdesc: 'desc',
            viewrecords: true

        });
    });
Posted
Updated 8-May-13 5:43am
v2
Comments
Member 9581488 8-May-13 11:57am    
Is your method returns the required data?
cation: 'EmplyoeeDetails', // it should be caption:
Are you getting any error in console?
Member 9507975 26-Sep-13 21:38pm    
this may not be a error but is definately a mistake

this is wroing
pager: $('#pager'),

should be

pager: #pager,

also
dataType: 'json',

should be

datatype: 'json',
Please check FireBug Console tab in FireFox, if there are any errors/exceptions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900