Wednesday, July 5, 2017

Web Form binding field values


 Sitecore.Web.UI.WebControls.Sublayout sublayout = this.Parent as Sitecore.Web.UI.WebControls.Sublayout;
            string ds = sublayout.DataSource;
            Item dsItem = Sitecore.Context.Database.Items.GetItem(ds);
            scTitle.Item = dsItem;

<sc:Text runat="server" ID="scTitle" Field="Title"/>

I had to add scTitle to the designer file manually. For some reason Visual Studio would not create one for me.

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace SfN.layouts.Brainfacts2.sublayouts
{


    public partial class Test
    {
        /// <summary>
        /// txtBodyText control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::Sitecore.Web.UI.WebControls.Text scTitle;
    }
}

No comments:

Post a Comment