1

老实说,我不确定数据绑定是否是实现这一目标的正确技术,所以如果有人能启发我,我将不胜感激。

基本上我要做的就是将一个对象从当前页面传递到一个网络用户控件中(代码简化):

示例页面.aspx

<div>
    <EC:AttachmentsView ID="AttachmentsView1" Attachments=<%# this.PageAttachments %> runat="server" />
</div>

ExamplePage.aspx.cs

public partial class ExamplePage : ProductBase
{
    private LinkItemCollection _pageAttachments;
    public LinkItemCollection PageAttachments
    {
        get { return _pageAttachments; }
    }

    public ExamplePage()
    {
        this.Load += new EventHandler(this.Page_Load);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        // Accessing and assigning attachments (EPiServer way)
        _pageAttachments = CurrentPage["Attachments"] as LinkItemCollection ?? new LinkItemCollection();
    }
}

附件视图控件具有用于AttachmentLabel属性的设置器和获取器。

附件视图.ascx.cs

namespace Example.Controls
{
    [ParseChildren(false)]
    public partial class AttachmentsView : EPiServer.UserControlBase
    {
        private string _label;
        public string Label
        {
            get { return _label; }
            set { _label = value; }
        }

        private LinkItemCollection _attachments;
        public LinkItemCollection Attachments
        {
            get { return _attachments; }
            set { _attachments = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (_attachments == null)
            {
                _attachments = CurrentPage["DefaultAttachments"] as LinkItemCollection ?? new LinkItemCollection();
            }
        }
    }
}

我正处于希望将来自 ExamplePage 的页面附件传递到 AttachmentsView 控件但 _attachments 属性为空的阶段。

我正在尝试做的事情可能吗?数据绑定是正确的技术吗,如果是的话,有没有人知道比可怕的 MSDN 文档更容易解释这些概念的材料?

我知道我可能可以通过以编程方式呈现控件来实现这一点,但我想先尝试这种方法。

4

0 回答 0