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

发布于 2024-09-11 00:50:49 字数 1098 浏览 1 评论 0 原文

因此,我在 UpdatePanel 中有一个 ListView (指派列表视图),并由同一 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 个元素(元素数量与当前人员之前选择的人员匹配)。

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

So I have a ListView (assignmentsListView) in an UpdatePanel, being filtered by a DropDownList in the same UpdatePanel. The DropDownList has a list of persons in it and uses autopostback, and the ListView shows the tasks those persons are assigned to.

I am trying to use code similar to this:

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); 
    }

}

When I first load the page, the DropDownList shows the first person in the list, and the ListView correctly shows that persons tasks.

If I then select a person who I know has zero tasks, I get an error at the RegisterPostBackControl() method, saying the passed-in control cannot be null.

When debugging, at the RegisterPostBackControl method, it shows that the ListView Items collection has >0 elements in it (the number of elements matches the person selected before the current person).

What's going on? Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

或十年 2024-09-18 00:50:49

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

In Asp.Net Web Forms applications, the order of events are not always what you'd want. For your case, the new person selection is probably applied after this method is executed. The best thing you could do is force databindings in an earlier event (like Page_Init)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文