2

我正在绑定到 SiteMapDataSource(分层)。

我正在重写 PerformDataBinding 以从数据源中获取数据。

页面加载时一切正常。但是当我在页面上的任何位置执行回发时,不会调用 PerformDataBinding 方法,实际上,不会呈现任何菜单项(未调用 PerformDataBinding)。

4

1 回答 1

3

不知道为什么会这样,但我有一个解决办法。令人惊讶的是,我能找到的每个 HierarchicalDataBoundControl 示例(甚至来自 msdn)都是这样做的。但是,这里有一个解决方法。

    private bool dataBound = false;
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        if (this.Page.IsPostBack)
        {
            this.DataBound += delegate { dataBound = true; };
            this.Page.Load += delegate { if (!dataBound) DataBind(); };
        }
    }
于 2010-04-27T12:28:56.060 回答