Showing posts with label Iterating through a List. Show all posts
Showing posts with label Iterating through a List. Show all posts

Monday, August 2, 2010

Use Delegate to Delete an Item from a List

Iterating through the list items is quite a simple task when delegates are in place.

 
protected void GrvUploads_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.ToString() == "DeleNow")
        {
            List oUploader = Session["UploadedFiles"] as List;
            if (oUploader != null)
            {
                oUploader.Remove(oUploader.Find(delegate(UploadEntity oEntity)
                {
                    return (oEntity.UploadID == Convert.ToInt64(e.CommandArgument));
                }
                ));
            }
            Session["UploadedFiles"] = oUploader;
            BindUploadGrid();
        }
    }