Is it possible to edit items in a dataview webpart using javascript from a content editor webpart on the same page. What methods would I use?

What I want to do is manipulate certain columns in a list based off the data in the DVWP, for example. I have a filtered DVWP with 30 items. With a button click in the CEWP I want to change all the items status field to "Complete" by looping through the id's of those items. Judging from looking at a few views with SP Designer I may need to loop through some XML code.

I know how to connect to the list with ecmascript and make the changes, I'm just not sure how I'd go about seeing the data on the DVWP from the CEWP. Any direction would be appreciated. Thanks in advance!

1 Answer 1


Your data view web part will only refresh on page load by default. Since your code runs in response to a button click, modifying the data, your data view is now displaying stale data that is no longer accurate. There are three ways you can handle this:

  1. Refresh the page. i.e. window.location = window.location;. This is easy to accomplish, and guaranteed to be accurate, but causes a not-so-neat page reload.

  2. use the ajax refresh option on the DVWP. The user will have to wait out the refresh cycle to see the updates. I've never used this so your mileage may vary.

  3. If you want to get really slick you can use jQuery to update the DOM representation of the cell in question. This approach is "faking" the visual update of the web part, but since you've changed the back-end data the appearance should match the reality. To do this you need to figure out how to reference the td in question. A simple representation might look something like this but would ultimately depend on the rendering of your web part. You will need to do some work to make this work in your environment (not to mention make it flexible and robust). Assume the "Status" field in the web part is the 6th cell in the table row:

    $("tr.ms-itmhover td:eq(6)").text("Closed");

If you are in a rush and/or unsure about your JavaScript abilities, go for option 1. If you have some time and the chops to pull it off, go for option 3.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.