The ListView control: A tip how to insert ItemTemplate into LayoutTemplate

  1. Add an HTML element to the <LayoutTemplate> container (your item template will be nested in this element).
  2. Set the element's ID to itemPlaceholder. Otherwise the ASP.NET template parser will throw an error.


Consider the following fragment of a web form:
<asp:ListView ID="ListView1" DataSourceID="XmlDataSource1"
    <div runat="server" id="itemPlaceholder" />
    <div style="clear:both">
      <div style="float:left"><%# Eval("title")%></div>
      <div style="float:left"><%# Eval("author")%></div>
This markup will output HTML markup similar to the one below:
<div> <!-- results from <div runat="server" id="itemPlaceholder" /> -->
  <div style="clear:both">
    <div style="float:left">Secrets of Silicon Valley</div>
    <div style="float:left">Sheryl Hunter</div>
  <div style="clear:both">
    <div style="float:left">Straight Talk About Computers</div>
    <div style="float:left">Dean Straight</div>


Popular posts from this blog


jQuery | remove inline style