【问题标题】:difference between item template and layout template项目模板和布局模板之间的区别
【发布时间】:2011-02-10 09:49:50
【问题描述】:

项目模板和布局模板有什么区别。只有在布局模板中我们有关于设计的信息?或其他任何东西。我无法理解项目模板..请解释..!

除了这个,我在这样的项目中有查询

SELECT TOP (1) ProductName, UnitPrice FROM Products ORDER BY NEWID()

这里 NEWID() 是什么意思?它是与sqlserver相关的预定义函数吗?我下载的项目中没有任何 newid() 函数。如果是预定义的函数,那么它可以做什么?

谢谢

【问题讨论】:

    标签: asp.net data-binding


    【解决方案1】:

    ListView 控件的主要布局是通过定义一个 LayoutTemplate 来创建的。 LayoutTemplate 将包含充当数据占位符的控件,例如 Table、Panel、Label 或 HTML 控件(例如 table、div 或 span 元素),它们的 runat 属性设置为“server”。 项目模板是主要模板,它将以重复的方式显示绑定到 ListView 的数据。此模板通常包含数据绑定到数据列或其他单个数据元素的控件。这两个模板是必需的。

    GroupTemplate 将用于对项目进行分组。 EditItemtemplate、SelectedItemTemplate、InsertItemTemplate 在插入、编辑、选择等特定操作中显示。 ItemSeparatorTemplate、GroupSeparatorTemplate 分别用于将单个项目和分组项目分开。

    这很重要ItemPlaceholderID="itemPlaceholder"

    <asp:ListView runat="server" ID="ListView1" ItemPlaceholderID="itemPlaceholder">
    <LayoutTemplate>
         <table border="0" cellpadding="1">
          <tr style="background-color:#E5E5FE">
           <th align="left"><asp:LinkButton ID="lnkId" runat="server">Id</asp:LinkButton></th>
           <th align="left"><asp:LinkButton ID="lnkName" runat="server">Name</asp:LinkButton></th>
           <th align="left"><asp:LinkButton ID="lnkType" runat="server">Type</asp:LinkButton></th>
           <th></th>
          </tr>
          <tr id="itemPlaceholder" runat="server"></tr>
         </table>
        </LayoutTemplate>
        <ItemTemplate>
          <tr>
           <td><asp:Label runat="server" ID="lblId"><%#Eval("ID") %></asp:Label></td>
           <td><asp:Label runat="server" ID="lblName"><%#Eval("FirstName")+" 
            "+Eval("LastName") %></asp:Label></td>
           <td><asp:Label runat="server" ID="lblType"><%#Eval("Type") %></asp:Label></td>
           <td></td>
          </tr>
        </ItemTemplate>
        <AlternatingItemTemplate>
          <tr style="background-color:#EFEFEF">
           <td><asp:Label runat="server" ID="lblId"><%#Eval("ID") %></asp:Label></td>
           <td><asp:Label runat="server" ID="lblName"><%#Eval("FirstName")+" "+
            Eval("LastName") %></asp:Label></td>
           <td><asp:Label runat="server" ID="lblType"><%#Eval("Type") %></asp:Label></td>
           <td></td>
          </tr>
        </AlternatingItemTemplate>
    </asp:ListView>
    

    参考链接:reference sitecode project reference

    【讨论】:

      【解决方案2】:

      看起来您正在使用 ListView 控件。

      ItemTemplate 属性仅适用于绑定到控件的数据项。 LayoutTempate 允许您为其他所有内容定义布局。

      假设您想使用 .您的 LayoutTemplate 将包含您的表定义,其中包含 ID 为“itemPlaceHolder”的单个空行

      &lt;tr id="itemPlaceHolder" runat="server" /&gt;

      然后,您的项目模板将定义您的 s 应该如何呈现。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-08-04
        • 1970-01-01
        • 1970-01-01
        • 2013-01-06
        • 1970-01-01
        • 2016-09-13
        • 1970-01-01
        相关资源
        最近更新 更多