【发布时间】:2010-08-30 07:59:04
【问题描述】:
我正在努力更新 List 中的业务对象。
我正在使用复选框列表
- 单击复选框列表项时
- 我检查它是否存在,如果存在我将其标记为脏(意味着用户取消选中一个项目)
-
如果没有,我在列表中添加一个新项目(意味着用户点击了一个新项目) 并将其存储在视图状态
如何使用脏对象更新通用列表? 在表单更新时,我是否会分别列出脏对象和新对象以发送到 DB 层,或者您会推荐任何其他方式吗?
这是我的代码,抱歉逻辑不好,我只是个初学者=(
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;
}
}
【问题讨论】:
标签: c# asp.net business-objects