Click here to Skip to main content
15,793,452 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a form representing a "job". Under that job is a list of items I've associated with the job. The user can add or delete items from the job.

A job has its own SQL table but there's also an Item table. When a job is created, any items in the job list are added to the Item table with a JobID linking them to the job.

Everything works just fine as it is - I can create, view or delete a job. The problem I have is how to approach the Update process. The simple (but not very elegant) way is as follows:

On loading the job form, and having edited the job list, and clicking "Update":
- Delete all items in the Item SQL table relating to the job.
- Add all the items from the job list to the table.

So in other words, each time I update, I effectively remove all items associated with the job and rewrite them back to the database. This is no problem where there are not too many items plus the code is simple. However, I'm looking for a *better* approach and I'm open to suggestions!

Thanks :)
Posted

1 solution

A more elegant solution would be to use some client-side script and to keep track of what elements of the job you've rendered on the client.

Think about your feed in Facebook. When you hover over a row, you're presented with different modification options (update, delete, hide, like, etc). Often, when you click on these, the UI changes to reflect your executed intent (something fades out, is redrawn, reworded or otherwise). This is client-side Ajax working with server-side code.

Consider what you users would like to do.

It's likely the users would want to leave items. So let them ;)

It's likely they may wish to delete an item. Render an 'x' image next to the line and, when clicked, call a web method that removes that ID from the table.

It's likely that they would want to update (or modify) a single element. Render a pencil beside the row and, when clicked, reveal an update interface of whatever sort is appropriate for your row of data, and send the update via Ajax to persist the changes.

There are some samples here[^] using ASP.NET and jQuery/jQuery UI together to make things like this happen.

Another thing to consider...if you do leave it as is, why not add a CreateDate field and a 'deleted' field. This would allow you to keep a history of Job iterations/modifications and you wouldn't need to delete the records, just mark them as 'deleted=true' and not render them on the page.

Cheers,
-jc
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900