我试图了解这里发生的生命周期。我有一个 asp 列表视图,我在其中获取项目 ID 并将它们写入这样的列表。
protected void ShareWith_OnItemBound(object sender, ListViewItemEventArgs e)
{
if (!IsPostBack)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
ListViewDataItem currentItemId = (ListViewDataItem)e.Item;
System.Web.UI.WebControls.DataKey currentDataKey = this.lvShareWithPanel.DataKeys[currentItemId.DataItemIndex];
int FriendId = Convert.ToInt32(currentDataKey["SharedUserId"]);
CurrentList.Add(FriendId);
}
}
}
我的列表是在方法之外定义的
private List<int> CurrentList = new List<int>();
之后,用户将一些新项目添加到列表中,然后单击 asp 按钮继续。我正在比较当前列表与新列表,但在单击按钮后在调试中观察我发现我的列表“CurrentList”现在为空。为什么在任何方法之外的列表可能会受到影响?
感谢帮助理解