Hello fellows, I am trying hard to update a business object inside a List<>.
I am using a checkbox list
- When a checkbox list item is clicked
- I check if it exists, if yes I mark it as Dirty (means the user unchecks an item)
If not, I add a new item to the list (means the user clicks a new item) and store it in view state
How do I update the Generic List with the Dirty Object ? On form update, do I foreach and make separate lists of dirty and new objects to send to DB layer or would you recommend any other way ?
Here is my code, sorry about the bad logic I am just a starter =(
protected void cblExclusions_SelectedIndexChanged(object sender, EventArgs e)
{
if (cblExclusions.SelectedIndex != -1)
{
ftExclusions myExclusion=new ftExclusions(); // Business object
ftExclusionsList myExclusionList=new ftExclusionsList(); // Business Obj. List
int excId = Convert.ToInt32(cblExclusions.SelectedValue.ToString()); // value of checkbox list item which is clicked
ftExclusionsList tempList = (ftExclusionsList)ViewState["ftExclusionList"];
ftExclusions isExist =tempList.Find(delegate(ftExclusions tmpExclusion)
{
return (tmpExclusion.excluId == excId);
});
if (isExist != null)
{
isExist.isDirtyExclusion(); // Mark as dirty
tempList. // stuck here I don't grasp how to save this back to the list
}
else
{
myExclusion = new ftExclusions();
myExclusion.excluId = excId;
myExclusion.fTrtID = Convert.ToInt32(lblTreatyNo.Text);
myExclusion.ftExcluId = -1; //new record
myExclusion.isNewExclusion(); // Mark as new
tempList.Add(myExclusion);
}
ViewState["ftExclusionList"] = tempList;
}
}