Categories | Question details Back To List | ||
Grid Update Iam trying to implement the dataprocessor sample in asp.net 2.0 and Iam able to implement the get operation page but iam having problems with the update. Here is the code which iam using Get.aspx.cs: SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); SqlCommand cmd = new SqlCommand("SELECT * FROM Employee", con); SqlDataReader dr; Response.ContentType = "text/xml"; Response.ContentEncoding = Encoding.UTF8; con.Open(); dr = cmd.ExecuteReader(); Response.Write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); Response.Write("<rows>"); int i=1; while(dr.Read()) { Response.Write("<row id=\""+(i++)+"\">"); Response.Write("<cell>" + dr[0].ToString() + "</cell>"); Response.Write("<cell>" + dr[1].ToString() + "</cell>"); Response.Write("<cell>" + dr[2].ToString() + "</cell>"); Response.Write("</row>"); } Response.Write("</rows>"); con.Close(); Response.End(); Update.aspx.cs: SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); SqlCommand cmd = new SqlCommand("UPDATE Employee SET First_Name='"+Request["First_Name"].ToString()+"', Last_Name='"+Request["Last_Name"].ToString()+"' WHERE Emp_ID='"+Request["Emp_ID"].ToString()+"'", con); Response.ContentType = "text/xml"; Response.ContentEncoding = Encoding.UTF8; Response.Write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); con.Open(); cmd.ExecuteNonQuery(); con.Close(); string action = "update"; string id = Request["Emp_ID"].ToString(); Response.Write("<data>"); Response.Write("<action type='"+action+"' sid='"+id+"' tid='"+id+"'/>"); Response.Write("</data>"); Response.End(); GridUpdate.aspx: <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Edit</title> <link rel="STYLESHEET" type="text/css" href="dhtmlxgrid.css"/> <link rel="STYLESHEET" type="text/css" href="dhtmlxgrid_skins.css"/> <script type="text/javascript"> hF="codebase/"; </script> <script type="text/javascript"> _css_prefix="/codebase/"; _js_prefix="/codebase/"; </script> <script type="text/javascript" src="dhtmlxcommon.js"></script> <script type="text/javascript" src="dhtmlxgrid.js"></script> <script type="text/javascript" src="dhtmlxgridcell.js"></script> <script type="text/javascript" src="dhtmlxgrid_excell_calendar.js"></script> <script type="text/javascript" src="dhtmlxdataprocessor.js"></script> </head><body> <table width="600"><tr><td><div id="gridbox" width="100%" height="250px" style="background-color:white;overflow:hidden"></div> </td></tr><tr><td><div id="messanger"> </div> <input type="Button" onclick="myDataProcessor.sendData()" id="updatebutton" value="Update" style="display:inline;"/> </td></tr> </table><br/> <script type="text/javascript"> mygrid = new dhtmlXGridObject('gridbox'); mygrid.setImagePath("codebase/imgs/"); var flds = "ID,First Name,Last Name"; mygrid.setHeader(flds); mygrid.setInitWidths("50,150,120"); mygrid.setColAlign("right,left,left"); mygrid.setColTypes("ed,ed,ed"); mygrid.setColumnIds("Emp_ID,First_Name,Last_Name"); mygrid.setSkin("light"); mygrid.setColSorting("str,str,str"); mygrid.init(); mygrid.loadXML("Get.aspx"); myDataProcessor = new dataProcessor("Update.aspx"); myDataProcessor.enableDataNames(true); myDataProcessor.setVerificator(1); myDataProcessor.setVerificator(3,checkIfNotZero); myDataProcessor.setUpdateMode("off");//available values: cell (default), row, off myDataProcessor.defineAction("error",myErrorHandler); myDataProcessor.setTransactionMode("GET"); myDataProcessor.init(mygrid); function myErrorHandler(obj){ alert("Error occured.\n"+obj.firstChild.nodeValue); myDataProcessor.stopOnError = true; return false;} function checkIfNotZero(value,colName){ if(value.toString()._dhx_trim()=="0"){ showMessage(colName+ " should not be 0"); return false; }else return true;} function showMessage(msg){ var msger = document.getElementById("messanger"); msger.innerHTML = msg; clearTimeout(toRef); toRef = setTimeout("showMessage(' ')",5000);} function doOnAutoupdateChecked(state){ if(state){ document.getElementById("updmdflt").click(); }else myDataProcessor.setUpdateMode('off'); document.getElementById('updatebutton').style.display=state?'none':'inline'; document.getElementById('updatemodes').style.display=state?'':'none'; } var toRef; </script> </body> </html> Iam getting an error "Microsoft JScript runtime error: '_cellType' is null or not an object" in dhtmlxgrid.js file on line 213. I need some help to get this working. Answer posted by Support on Jan 14, 2008 08:42 The problem is in next line >>myDataProcessor.setVerificator(3,checkIfNotZero); You are setting the verificator on column with index 3, but there is no such column ( column indexes are zero based, so in your case you are having only index 0,1,2 ) |