所以我在 UpdatePanel 中有一个 ListView (assignmentsListView),由同一个 UpdatePanel 中的 DropDownList 过滤。DropDownList 中有一个人员列表并使用自动回发,ListView 显示分配给这些人员的任务。
我正在尝试使用与此类似的代码:
protected void assignmentsListView_DataBound(object sender, EventArgs e)
{
string resFirstName = Utilities.getResourceFirstName(resDdl.SelectedValue);
if (assignmentsListView.Items.Count <= 0)
{
//Show error message
}
else
{
//Try to find the ImageButton in the ListView's header template.
ImageButton exportButton = (ImageButton)assignmentsListView.FindControl("ImageButton3");
//Register this button as a PostBack event in the Master Page
ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
ScriptManager.RegisterPostBackControl(exportButton);
}
}
当我第一次加载页面时,DropDownList 显示列表中的第一个人,而 ListView 正确显示了该人员的任务。
如果我然后选择一个我知道有零任务的人,我会在 RegisterPostBackControl() 方法中收到错误,说传入的控件不能为空。
调试时,在RegisterPostBackControl 方法中,显示ListView Items 集合中有>0 个元素(元素数量与当前人之前选择的人匹配)。
这是怎么回事?有什么建议么?