views:

27

answers:

2

Hello fellows, Good day. I am having a Form where

  Table SelectedItems                Table AvailableItems
 RecordID  CheckBoxID                CheckBoxID     Description
    1           1                         1           'Tomatoes'
    1           2                         2           'Potatoes'   
    1           4                         3           'Mangoes' 
    2           1                         4           'Apples'  
    2           2     
  1. Now I have to edit the SelectedItems for RecordID 1
  2. For that purpose I made a CheckBox list and populate it with AvaialbeItems
  3. Then I looped and checked the SelectedItems for RecordID 1
  4. User selects some new rows from the available list (along with old ones, he may deselect some as well)

Now I want to update the selected records, problem being I want to know only new records to insert.

Both Tables are being returned as Business Object Lists<> , How do I compare the lists and extract only changed/new rows ?

Please advice me. I am using webforms on VSS 2005.

+1  A: 

When you select record(s), could you update the business object(s) and dirty them? What I mean is create a class variable that will serve as a flag that you can check to see if it was changed or new. The select new rows (or old) I would think fire an event that you can use to modify the selected row's business object.

Then when you go through your Lists you just need to check the business object flag that yields the status of change/new.

Robb
Thanks that seems like a nice idea, how do I access my business object for the row which is being checked ?
Popo
I'm not sure but I would suspect when you select a row you should be within some event that you can use to get the business object. So if I select a row, an event is raised which I could have code for that takes the business object associate with the row and marks it. EDIT: I don't have my c# compiler in front of me is why i'm not sure.
Robb
Thanks, I got it sorted out after sometime. I had to make a base class and inherit it when required. But the solution was based on your initial suggestion. =)
Popo
A: 

If the system is already on production server and running stably, please ignore my answer. If it's still under planning/designing/programming stage, I think probably a slight DB change will make everything much more easier.

 Table SelectedItems 
RecordID  CheckBoxID  IsSelected
    1           1        true
    1           2        true
    1           3        false
    1           4        true

That is, for a certain RecordID and CheckBoxID, you don't need to query the table to find if there is a corresponding record(which means it's selected). In the new design, there is always such a record, with a IsSelected status.

Meanwhile, this design is also very easy for maintanance in your web pages. What you change is just IsSelected value for a certain row, you don't need to care about "Oh, do I need to delete one row or add one?" "Is the data of this row dirty or not?"...things become easier.

Danny Chen