Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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 ?

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

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!

share|improve this answer
    
+1 "But if you are already in C#, why not just use the Object Model?" –  RJ Cuthbertson Nov 29 '12 at 14:26
    
But how Use It. I must send a IDis from C# by the Hiddenfield, or somthing better ? –  Grzegorz Z Nov 29 '12 at 14:28
    
Can it be do from Event Receiver ? –  Grzegorz Z Nov 29 '12 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. –  Norbert Nov 29 '12 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. –  Norbert Nov 29 '12 at 15:48
show 3 more comments

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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