Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Tuesday, October 09, 2012

Delete the SharePoint ListItem using ECMA Script

Note:-
Use Delete() function in Delete Button onclick event, for DropDown Binding View my Previous article posted before this.


function Delete()
{
                ExecuteOrDelayUntilScriptLoaded(DeleteRecord, "sp.js");
}
function DeleteRecord()
{
                if(document.getElementById("ddlItemID").selectedIndex==0)
                {
                                alert('Please Select UserName');
                                return false;
                }
                var context = new SP.ClientContext.get_current();
    var web = context.get_web();
    var list = web.get_lists().getByTitle('Login');
    var LoginRecord = list.getItemById(document.getElementById("ddlItemID").options(document.getElementById("ddlItemID").selectedIndex).value);
    LoginRecord.deleteObject();
    context.executeQueryAsync(Function.createDelegate(this, this.DeleteSuccess), Function.createDelegate(this, this.DeleteFailed));
}

function DeleteSuccess()
{
                alert('Record Deleted Successfully');
                document.getElementById("tdItemID").innerHTML="";
                Bind();
                document.getElementById("ddlItemID").selectedIndex=0;
               
}

function DeleteFailed(sender, args)
{
                alert('Delete Failed');
}

No comments:

Post a Comment