0

所以我在 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 个元素(元素数量与当前人之前选择的人匹配)。

这是怎么回事?有什么建议么?

4

1 回答 1

0

在 Asp.Net Web Forms 应用程序中,事件的顺序并不总是您想要的。对于您的情况,执行此方法后可能会应用新的人员选择。您可以做的最好的事情是在较早的事件中强制数据绑定(如 Page_Init)

于 2010-07-23T18:23:16.947 回答