<?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: jqGrid + dropdown lists + asp.net MVC</title>
	<link>http://www.trirand.com/blog/?page_id=393/help/jqgrid-dropdown-lists-asp-net-mvc</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/jqgrid-dropdown-lists-asp-net-mvc/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>chandinipt on jqGrid + dropdown lists + asp.net MVC</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/jqgrid-dropdown-lists-asp-net-mvc#p24888</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/jqgrid-dropdown-lists-asp-net-mvc#p24888</guid>
        	        	<description><![CDATA[<p>Hi,</p>
<p>Can somebody help me resolve an issue I am having with jqGrid and dropdown lists please?&#160; I have looked at the questions on SO but the solutions do not help me.</p>
<p>I have two drop down lists - category and subCategory.&#160; I want the subCategory value to be dependent on the category.&#160; I am using Form-based editing<br />&#160;&#160;&#160; I can get this working in the following cases no problem<br />- when i am adding a new row, the drop downs work fine.&#160; SubCategory is initially set to just the &#39;Select&#39; string and when I select a category, the subcategory values are correctly updated. <br />- ****I create any new row**** and then go&#160;back in my grid, click on any other row to edit the data, the subCategory value is correctly displayed from the database.&#160;</p>
<p>&#160; If however, I go into my page and just try to edit a row in the form (without first creating a new row), the subcategory is not set correctly from the database.&#160; And just shows up empty.&#160; I have tried using dataInit on both fields but it doesn&#39;t even fire!!!!&#160;</p>
<p>These are the relevant code lines.&#160; <br />jqGrid View:-</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; { name: &#39;categoryId&#39;, index: &#39;categoryId&#39;, width: 100, align: &#39;left&#39;, sortable: true, editable: true, edittype: &#39;select&#39;,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; editoptions: { dataUrl: &#39;/Admin/GetCategories&#39;,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dataEvents: [<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; { type: &#39;change&#39;,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; fn: function (e) {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var v = $(e.target).val();<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; setSubCategory(v);<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ]<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; },<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; editrules: { edithidden: true }, searchtype: "text", searchoptions: { sopt: [&#39;cn&#39;, &#39;eq&#39;, &#39;ne&#39;, &#39;bw&#39;, &#39;ew&#39;, &#39;nc&#39;] }<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; },<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; { name: &#39;subCategoryId&#39;, index: &#39;subCategoryId&#39;, width: 100, align: &#39;left&#39;, sortable: true, editable: true, edittype: &#39;select&#39;,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; editoptions: { dataUrl: &#39;/Admin/GetSubCategoriesForCategory&#39; },<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; editrules: { edithidden: true }, searchtype: "text", searchoptions: { sopt: [&#39;cn&#39;, &#39;eq&#39;, &#39;ne&#39;, &#39;bw&#39;, &#39;ew&#39;, &#39;nc&#39;] }<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }....</p>
</p>
<p>&#160;&#160;&#160; function setSubCategory(category) {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; $.ajax({<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; url: &#39;/Admin/GetSubCategoriesForCategory&#39;,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; data: { &#39;categoryId&#39;: category },<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; type: &#39;GET&#39;,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dataType: &#39;html&#39;,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; success: function (data) {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $("#subCategoryId").html(data);<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; });<br />&#160;&#160;&#160; }</p>
<p>And my controller action</p>
<p>&#160;&#160;&#160; public string GetSubCategoriesForCategory(int? categoryId)<br />&#160;&#160;&#160; {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (categoryId == null)<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return GetEmptySelect();&#160;&#160; //Just returns a Select with no options</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; StringBuilder result = new StringBuilder();<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; result.Append(defaultVal);&#160; //this is the &#39;Select&#39; option<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (categoryId != null)<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; foreach (var c in db.categories.Where(c =&#62; c.parentID == categoryId).ToList())<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; result.Append("&#60;option value=" + c.ID + " &#62; " + c.desc + " &#60;/option&#62; ");<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; return result.ToString();<br />&#160;&#160;&#160; }&#160;</p>
<p>As I mentioned before, I did try using the dataInit on categories to set the dataUrl of the sub-categories, but I keep getting an undefined value instead for some reason.&#160;</p>
<p>P.S:- Not sure if this is relevant or not, but I&#160;cannot get many of the events to fire in the jqGrid.&#160; I also cannot get the cell editing to work either, just freezes the grid and I cannot select any row etc.&#160; I&#39;m using IE8.</p>
<p>Thank you</p></p>
]]></description>
        	        	<pubDate>Thu, 13 Oct 2011 12:45:50 +0300</pubDate>
        </item>
</channel>
</rss>