Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MVC
Hi, iam using jqgrid using json result but grid is not populating plz help me
here is my code
for controller:
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:
$(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 8-May-13 0:40am
Edited 8-May-13 6:43am
(no name)499K
v2
Comments
Member 9581488 at 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 at 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',
Tadit Dash at 8-May-13 12:29pm
   
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)

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 210
2 BillWoodruff 205
3 DamithSL 165
4 Tomas Takac 144
0 OriginalGriff 5,130
1 DamithSL 4,157
2 Maciej Los 3,670
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,821


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 8 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100