代码之家  ›  专栏  ›  技术社区  ›  Matthew Jones

当实际项<=0时,ListView数据绑定显示项>0

  •  0
  • Matthew Jones  · 技术社区  · 14 年前

    因此,我在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项集合中有>0个元素(元素的数量与在当前人员之前选定的人员匹配)。

    发生什么事?有什么建议吗?

    1 回复  |  直到 14 年前
        1
  •  0
  •   sukru    14 年前

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