c# - Display CategoryName in JQGrid with Product Name and Price -


i have product model below

public class product { public int productid { get; set; } public string productname { get; set; } public int categoryid {get;set;} public float price { get; set; } public category category { get; set; } } 

i have read category id , category name in below method , want display product name, category name , price in jqgrid displays product name , price not cayegoryname.

public jsonresult showproducts(string sidx, string sord, int page, int rows)         {             int pageindex = convert.toint32(page) - 1;             int pagesize = rows;              businesslayer buslayer = new businesslayer();              list<product> prodlist = new list<product>();             prodlist = buslayer.readproducts();              foreach (var prd in prodlist)             {                 prd.category = buslayer.getcategorybyid(prd.categoryid);                             }              int recordcount = prodlist.count;             var totalpages = (int)math.ceiling((float)recordcount / (float)rows);             var jsondata = new             {                 total = totalpages,                 records = recordcount,                 rows = prodlist                             };              return json(jsondata, jsonrequestbehavior.allowget);         } 

scrips display below,

$("#grid").jqgrid({         url: "/admin/showproducts",         datatype: 'json',         mtype: 'get',         colnames: ['id', 'product name', 'category name', 'price', 'catid'],         colmodel: [             { key: true, hidden: true, name: 'id', index: 'id', editable: true },             { key: false, name: 'productname', index: 'productname', editable: true },             { key: false, name: 'categoryname', index: 'categoryname', editable: true },             { key: false, name: 'price', index: 'price', editable: true },             { key: true, hidden: true, name: 'catid', index: 'catid', editable: true },             ],         pager: jquery('#pager'),         rownum: 5, ...... ...... ...... 

in product, productname of type string category property not of type string. converting category string type hold category name should done.

along that, in jqgrid properties colmodel name represent direct mapping properties. category, name should category category name. update made below,

$("#grid").jqgrid({         url: "/admin/showproducts",         datatype: 'json',         mtype: 'get',         colnames: ['id', 'product name', 'category name', 'price', 'catid'],         colmodel: [             { key: true, hidden: true, name: 'id', index: 'id', editable: true },             { key: false, name: 'productname', index: 'productname', editable: true },             { key: false, name: 'category', index: 'category', editable: true },             { key: false, name: 'price', index: 'price', editable: true },             { key: true, hidden: true, name: 'catid', index: 'catid', editable: true },             ],         pager: jquery('#pager'),         rownum: 5, 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -