<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
	<title>jQuery Grid Plugin - jqGrid - Topic: C# and JSON Object</title>
	<link>http://www.trirand.com/blog/?page_id=393/help/c-and-json-object</link>
	<description><![CDATA[Grid plugin]]></description>
	<generator>Simple:Press Version 5.7.5.3</generator>
	<atom:link href="http://www.trirand.com/blog/?page_id=393/help/c-and-json-object/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>csetzkorn on C# and JSON Object</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/c-and-json-object#p5584</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/c-and-json-object#p5584</guid>
        	        	<description><![CDATA[<p>Hi,</p>
<p>I am using entity framework and create JSON within ASP.NET MVC. I am using this prototype code and it works:</p>
<p>&#160;public JsonResult Data(string _search, string sord, string sidx)<br />{<br />&#160;&#160;&#160; var result = new JsonResult();</p>
<p>&#160;&#160;&#160; if( _search.Equals("true") == true ) // search - to be done<br />&#160;&#160;&#160; {</p>
<p>&#160;&#160;&#160; }<br />&#160;&#160;&#160; else<br />&#160;&#160;&#160; {<br />&#160;List&#60;test1&#62; list;</p>
<p>&#160;double count = _entities.test1.Count();<br />&#160;double number_of_requested_rows = Convert.ToDouble( Request.QueryString["rows"] );<br />&#160;double requested_page = Convert.ToDouble(Request.QueryString["page"]);<br />&#160;double total_pages = 0;<br />&#160;var page = new { page = requested_page.ToString() };</p>
<p>&#160;if (count &#62; 0)<br />&#160;{<br />&#160;&#160;&#160;&#160; total_pages = Math.Ceiling(count / number_of_requested_rows);<br />&#160;}</p>
<p>&#160;double start_index =&#160; (number_of_requested_rows * requested_page) - number_of_requested_rows;</p>
<p>&#160;if( start_index &#60; 0 )<br />&#160;{<br />&#160;&#160;&#160;&#160; start_index = 0;<br />&#160;}</p>
<p>&#160;if (sord.Equals("desc") == true)<br />&#160;{<br />&#160;&#160;&#160;&#160; list = _entities.test1.OrderBy(sidx, true).Skip((int)start_index).Take((int)number_of_requested_rows).ToList();<br />&#160;}<br />&#160;else<br />&#160;{<br />&#160;&#160;&#160;&#160; list = _entities.test1.OrderBy(sidx, false).Skip((int)start_index).Take((int)number_of_requested_rows).ToList();<br />&#160;}</p>
<p>&#160;var rows = from t in list<br />&#160;&#160;&#160; select<br />&#160;&#160;&#160; new<br />&#160;&#160;&#160; {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; id = t.pk,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; cell = new[]<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {<br />&#160;&#160;&#160;&#160; t.pk.ToString(),<br />&#160;&#160;&#160;&#160; t.col1,<br />&#160;&#160;&#160;&#160; t.col2,<br />&#160;&#160;&#160;&#160; t.col3<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br />&#160;&#160;&#160; };</p>
<p>&#160;object userdata = new{TYPE = "",MSG = "hello world"};</p>
<p>&#160;result.Data = new { total = total_pages, page = requested_page, records = count, userdata = userdata, rows };<br />&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160; return result;<br />}</p>
<p>Perhaps this helps it maps this simple table</p>
<p>pk int,</p>
<p>col1 char,</p>
<p>col2 char,</p>
<p>col3 char</p>
<p>I am sure it can be improved.</p>
<p>&#160;Christian</p>
]]></description>
        	        	<pubDate>Wed, 25 Mar 2009 03:38:59 +0200</pubDate>
        </item>
        <item>
        	<title>nsorochan on C# and JSON Object</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/c-and-json-object#p5579</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/c-and-json-object#p5579</guid>
        	        	<description><![CDATA[<p>I am a newbie and I am trying to create a valid json object, so the default jsonreader will be able to read it. The c# code I have is the following:</p>
<p>var gridData = new ViewDataDictionary();<br />
var gridRows = new ViewDataDictionary[1];<br />
gridRows[0] = new ViewDataDictionary();<br />
gridRows[0]["id"] = 2;<br />
gridRows[0]["cell"] = new object[]<br />
     {<br />
      2, "2009-03-23", "Test Client", 34.65, 5.34, 39.99,<br />
      "These are test notes which can be very long."<br />
     };<br />
gridData["page"] = 1;<br />
gridData["total"] = 1;<br />
gridData["records"] = 1;<br />
gridData["rows"] = gridRows;</p>
<p>It spits this out, which is obviously not seem correct as the data is not loaded in the grid:<br />
[{"Key":"page","Value":1},{"Key":"total","Value":1},{"Key":"records","Value":1},{"Key":"rows","Value"<br />
:[[{"Key":"id","Value":2},{"Key":"cell","Value":[2,"2009-03-23","Test Client",34.65,5.34,39.99,"These<br />
 are test notes which can be very long."]}]]}]</p>
<p>I am not sure what type of objects to use on the server side to create the json object.</p>
<p>thanx</p>
]]></description>
        	        	<pubDate>Tue, 24 Mar 2009 17:56:50 +0200</pubDate>
        </item>
</channel>
</rss>