ASP.NET - how to use jqgrid in asp.net

Asked By abhishek kalagoudra on 21-May-10 12:52 AM
i want to use jqGrid in my project (asp.net,c#)but dnt know how to integerate it in my project...plz help me with sample applicatioin
Arun Kumar Ramesh replied to abhishek kalagoudra on 21-May-10 01:16 AM
Hi Abishek,

Just check the below mentioned link. It gives steop by step example of how to use jpgrid and also demo code and its output is being displayed.

http://haacked.com/archive/2009/04/14/using-jquery-grid-with-asp.net-mvc.aspx


Hope this helps.

Regards,
Arun Ramesh
Arun Kumar Ramesh replied to abhishek kalagoudra on 21-May-10 01:18 AM
Abishek,

Also have a look at the link below. You may get some more ideas about it..

http://blogs.teamb.com/craigstuntz/2009/04/17/38229/


Regards,
Arun ramesh
abhishek kalagoudra replied to Arun Kumar Ramesh on 21-May-10 06:38 AM
in this function (frm the link provided)===> public ActionResult GridData(string sidx, string sord, int page, int rows) 
from where to fetch and pass the values of sidx and sord...in the query string we will get page and rows values only
plz if u can help with asp.net,C# code
i tried to do ths....
page == default.aspx <table id="list"></table>
<div id="pager"></div> 

jQuery(document).ready(function(){
  jQuery("#list").jqGrid({
    url:'example.aspx', //XMLFile2.xml
    datatype: 'xml',
    mtype: 'GET',
    colNames:['Inv No','Date', 'Amount','Tax','Total','Notes'],
    colModel :[
      {name:'invid', index:'invid', width:55},
      {name:'invdate', index:'invdate', width:90},
      {name:'amount', index:'amount', width:80, align:'right'},
      {name:'tax', index:'tax', width:80, align:'right'},
      {name:'total', index:'total', width:80, align:'right'},
      {name:'note', index:'note', width:150, sortable:false}
    ],
    pager: '#pager',
    rowNum:10,
    rowList:[10,20,30],
    sortname: 'invid',
    sortorder: 'desc',
    viewrecords: true,
    imgpath: '/scripts/css/ui_lightness/images',
    caption: 'My first grid'
  });
});

page == example.aspx.cs

onpage_load()
{
int page = Convert.ToInt32(Request.QueryString["page"]); //these values returned from Qry Str are 0's thus no records
int limit = Convert.ToInt32(Request.QueryString["rows"]);
int sidx = Convert.ToInt32(Request.QueryString["sidx"]);
int sord = Convert.ToInt32(Request.QueryString["sord"]);

if(sidx==null) sidx =1;

int count = ExecScal("SELECT COUNT(*) AS count FROM invheader");
    int total_pages=0;
    
if( count > 0 && limit > 0) {
    decimal cel = count / limit;
    total_pages = Convert.ToInt32(Math.Ceiling(cel));
  }
  else
  { total_pages = 0;
   }
if (page > total_pages) page=total_pages;
 
 int start = limit*page - limit;
 
if(start <0) start = 0;
 
 string str= "SELECT invid, invdate, amount, tax,total, note FROM invheader ";
           //str +=  "WHERE invid NOT IN (SELECT TOP " + start + " invid FROM invheader ORDER BY invid ASC) AND ";
           //str  += "invid IN (SELECT TOP " + limit + " invid FROM invheader ORDER BY invid ASC)";
           ////str += "ORDER BY "+ sidx +" "+  sord;

        DataTable dt = ExecDataTable(str);

        int cnt = dt.Rows.Count;

        Response.ContentType="text/xml;charset=utf-8";
 
string strxml = "<?xml version='1.0' encoding='utf-8'?>";
strxml +=  "<rows>";
strxml += "<page>" + page +"</page>";
strxml += "<total>"+ total_pages + "</total>";
strxml += "<records>"+ count + "</records>";
 
foreach(DataRow dr in dt.Rows)
 {
    strxml += "<row id='"+ dr["invid"] + "'>";            
    strxml += "<cell>"+ dr["invid"] + "</cell>";
    strxml += "<cell>"+ dr["invdate"] + "</cell>";
    strxml += "<cell>"+ dr["amount"] + "</cell>";
    strxml += "<cell>"+ dr["tax"] +"</cell>";
    strxml += "<cell>"+ dr["total"] + "</cell>";
    strxml += "<cell><![CDATA["+ dr["note"] + "]]></cell>";
    strxml += "</row>";
}
strxml += "</rows>";
 Response.Write(strxml);
 }