Add new Item and Edit Item in silverlight DataForm not correctly updating SharePoint List -



Add new Item and Edit Item in silverlight DataForm not correctly updating SharePoint List -

i trying create simple silverlight application hosted on sharepoint site. reading info list "testlist" , trying utilize dataform command edit, add together , delete info list. able delete fine. when seek add together adds new entry info item viewed , unable edit current items whatsoever. here code:

namespace sp2010 { public partial class mainpage : usercontrol { clientcontext context; list customerlist; listitemcollection allcustomers; public mainpage() { this.loaded += new routedeventhandler(mainpage_loaded); initializecomponent(); } void mainpage_loaded(object sender, routedeventargs e) { this.datacontext = this; context = new clientcontext(applicationcontext.current.url); customerlist = context.web.lists.getbytitle("testlist"); context.load(customerlist); camlquery camlquery = new camlquery(); camlquery.viewxml =@"<view><query></query><rowlimit>1000</rowlimit></view>"; allcustomers = customerlist.getitems(camlquery); context.load(allcustomers); context.executequeryasync(new clientrequestsucceededeventhandler(onrequestsucceeded), new clientrequestfailedeventhandler(onrequestfailed)); } private void onrequestsucceeded(object sender, clientrequestsucceededeventargs args) { dispatcher.begininvoke(displaylistdata); } private void onrequestfailed(object sender, clientrequestfailedeventargs args) { messagebox.show(args.errordetails + " " + args.message); } public observablecollection<spcustomers> printers { { if (printers == null) { printers = new observablecollection<spcustomers>(); foreach (listitem item in allcustomers) { printers.add(new spcustomers { ipaddress = item["title"].tostring(), create = item["make"].tostring(), model = item["model"].tostring(), xcord = item["x"].tostring(), ycord = item["y"].tostring(), id = convert.toint32(item["id"].tostring()) }); } } homecoming (printers); } } private observablecollection<spcustomers> printers; private void displaylistdata() { dataform1.datacontext = printers; } private void dataform1_editended(object sender, dataformeditendedeventargs e) { if (e.editaction == dataformeditaction.commit) { if (dataform1.isitemchanged) { customerlist = context.web.lists.getbytitle("testlist"); spcustomers printer = dataform1.currentitem spcustomers; listitem items = customerlist.getitembyid(printer.id); items["title"] = printer.ipaddress; items["make"] = printer.make; items["model"] = printer.model; items["x"] = printer.xcord; items["y"] = printer.ycord; items.update(); context.executequeryasync(onrequestsucceeded, onrequestfailed); } } } private void dataform1_addingnewitem(object sender, dataformaddingnewitemeventargs e) { customerlist = context.web.lists.getbytitle("testlist"); spcustomers printe = dataform1.currentitem spcustomers; listitemcreationinformation itemcreationinfo = new listitemcreationinformation(); listitem items = customerlist.additem(itemcreationinfo); items["title"] = printe.ipaddress; items["make"] = printe.make; items["model"] = printe.model; items["x"] = printe.xcord; items["y"] = printe.ycord; items.update(); context.executequeryasync(onrequestsucceeded, onrequestfailed); } private void dataform1_deletingitem(object sender, system.componentmodel.canceleventargs e) { spcustomers printer = dataform1.currentitem spcustomers; listitem olistitem = customerlist.getitembyid(printer.id); olistitem.deleteobject(); context.executequeryasync(onrequestsucceeded, onrequestfailed); } } }

and dataform:

<df:dataform itemssource="{binding}" height="276" horizontalalignment="left" margin="12,12,0,0" name="dataform1" verticalalignment="top" width="376" editended="dataform1_editended" addingnewitem="dataform1_addingnewitem" deletingitem="dataform1_deletingitem" commandbuttonsvisibility="all" />

thanks help.

update: changed reply in 7 hours when lets me

never mind figured out changed editended , deleted addingnewitem method entirely. have hide id field , working perfectly

private void dataform1_editended(object sender, dataformeditendedeventargs e) { if (e.editaction == dataformeditaction.commit) { customerlist = context.web.lists.getbytitle("testlist"); spcustomers printer = dataform1.currentitem spcustomers; listitem items; if (printer.id != 0) { items = customerlist.getitembyid(printer.id); } else { listitemcreationinformation itemcreationinfo = new listitemcreationinformation(); items = customerlist.additem(itemcreationinfo); } items["title"] = printer.ipaddress; items["make"] = printer.make; items["model"] = printer.model; items["x"] = printer.xcord; items["y"] = printer.ycord; items.update(); context.executequeryasync(onrequestsucceeded, onrequestfailed); } }

silverlight-4.0 sharepoint-2010 dataform

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -