我有一个 Sharepoint 2010 列表。我已经编写了事件接收器代码来更新项目添加事件中的字段值。我得到了正确的结果,但在我刷新列表之前它不会更新字段值。为什么?
代码:
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
SPWeb web = properties.OpenWeb();
SPList list = properties.List;
int highestValue = 0;
SPQuery query = new SPQuery();
query.Query = @"<OrderBy>
<FieldRef Name='NextNo' Ascending='FALSE' />
</OrderBy><RowLimit>1</RowLimit>";
SPListItemCollection itemcollection = list.GetItems(query);
if (itemcollection.Count > 0)
{
SPListItem item = itemcollection[0];
highestValue = Convert.ToInt32(item["NextNo"]);
}
SPListItem currItem = properties.ListItem;
currItem["NextNo"] = highestValue + 1;
currItem.Update();
}