因此,我在UpdatePanel中有一个ListView (assignmentsListView),它被同一个UpdatePanel中的DropDownList过滤。DropDownList中有一个人员列表,并使用autopostback,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个元素(元素的数量与在当前person之前选择的person匹配)。
到底怎么回事?有什么建议吗?
发布于 2010-07-24 02:23:17
在Asp.Net Web Forms应用程序中,事件的顺序并不总是您想要的。对于您的情况,新的person选择可能是在执行此方法之后应用的。你能做的最好的事情就是在一个较早的事件中强制数据绑定(比如Page_Init)
https://stackoverflow.com/questions/3321168
复制相似问题