Sitecore Swamp

Dive in the Sitecore Swamp

NAVIGATION - SEARCH

Sitecore Version History


REFERENCE:
  1. Kiran Patil: http://sitecorebasics.wordpress.com/2014/04/20/sitecore-cms-version-history/
  2. John West :  http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2011/05/Sitecore-ASPNET-CMS-Version-History.aspx
  3. Kim Hornung : https://www.blogger.com/feeds/36416442/posts/default

Workaround of data binding for LayoutTempate

Data binding doesn't work inside the LayoutTempate of ListView. The workaround is to utilize the LayoutCreated event to do find-and-assign:

Markup:
<asp:ListView runat="server" OnLayoutCreated="SelectedFiedls_OnLayoutCreated">
    <LayoutTemplate>
        <asp:Literal runat="server" ID="SeletectedFieldsTotal" /> Criteria selected for comparison:</h5>
            <asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
    </LayoutTemplate>
    <ItemTemplate>
        ...
    </ItemTemplate>
</asp:ListView>
Code-behind:
protected void SelectedFiedls_OnLayoutCreated(object senderEventArgs e)
{
     var selectedFieldsTotal = ((ListView)sender).FindControl("SeletectedFieldsTotal"as Literal;
     selectedFieldsTotal.Text = SelectedFields.Count().ToString();
}
------------------------------------------------------------------------------------------------------------------------------------------------------------
updated: 2014-01-17 11:49 AM

The method above has issues with ViewState, as the LayoutCreated event is raised when the layout template is created in the ListView control. Obvious, it's too early for ViesState.(see ASP.NET Page LifeCycle Overview)

If using my favorite ControlDataBind event handler:
protected void ControlDataBind(object senderEventArgs e)
{
    ((Control)sender).DataBind();
}
This work can be done like:
<asp:ListView runat="server" OnLayoutCreated="SelectedFiedls_OnLayoutCreated">
    <LayoutTemplate>
        <asp:PlaceHolder runat="server" OnLoad="ControlDataBind">
            <h5><%# SelectedFields.Count() %> Criteria selected for comparison:</h5>    
        </asp:PlaceHolder>
    </LayoutTemplate>
    <ItemTemplate>
        ...
    </ItemTemplate>
</asp:ListView>
Happy coding!!!