首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当Items <=实际为0时,ListView DataBound表示Items >0

当Items <=实际为0时,ListView DataBound表示Items >0
EN

Stack Overflow用户
提问于 2010-07-24 02:20:09
回答 1查看 729关注 0票数 0

因此,我在UpdatePanel中有一个ListView (assignmentsListView),它被同一个UpdatePanel中的DropDownList过滤。DropDownList中有一个人员列表,并使用autopostback,ListView显示分配给这些人员的任务。

我正在尝试使用类似如下的代码:

代码语言:javascript
复制
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匹配)。

到底怎么回事?有什么建议吗?

EN

回答 1

Stack Overflow用户

发布于 2010-07-24 02:23:17

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3321168

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档