0

I find aut a this article about to easy and fast delete a records from list: http://spservices.codeplex.com/discussions/245147 How could I use it ? Can I use it on cs files, if yes so how can I use it ? Where should it be written ?

2 Answers 2

5

I don't know about SPServices, but here is the method I am using to delete a record from a list.

function DeleteRecordFromList(listName,recordId){
  $.ajax({
    url: '/_vti_bin/listdata.svc/'+listName+'('+recordId+')',
    type: "DELETE",
    contentType: "application/json; charset=utf-8",
    success: function () {
        alert("Record has been deleted");
    },

    error: function (xhr, ajaxOptions, thrownError) {
        alert(xhr.status + " " + thrownError);
    }
  });
}

Be careful, the list name is case sensitive! If you want to do it from C#, you have instantiate an HttpRequest and call the same url as in the ajax call above. But if you are already in C#, why not just use the Object Model? Why to use jQuery? More about listdata.svc: http://msdn.microsoft.com/en-us/library/ff798339.aspx

I hope it helped!

8
  • +1 "But if you are already in C#, why not just use the Object Model?" Commented Nov 29, 2012 at 14:26
  • But how Use It. I must send a IDis from C# by the Hiddenfield, or somthing better ? Commented Nov 29, 2012 at 14:28
  • Can it be do from Event Receiver ? Commented Nov 29, 2012 at 14:29
  • 1
    Well, you could use a global javascript variable like: var ID = '<%= IdPropertyFromCodeBehind%>'; See [this] (sharepoint.stackexchange.com/questions/52713/…) post too, maybe. Commented Nov 29, 2012 at 14:31
  • 1
    Ok, so if I understood you correctly: you want to cascade delete items from the SecondList when you delete an item from the First list. In this case, please consider adding an extra column to the SecondList to hold the ID of the "parent" from the FirstList. Add an EventReceiver on ItemDeleting on the FirstList, and delete all items also from SecondList where secondListItem["ParentId"] == idBeingDeleted. Commented Nov 29, 2012 at 15:48
1

I am not repeating the steps for jQuery as it's already described by @Norbert, but you can have a look at this post for C# way

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.