2011-02-10 97 views
3

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

除了这个我有这样的

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

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

谢谢

回答

7

ListView控件的主布局是通过定义LayoutTemplate创建的。 LayoutTemplate将包含充当占位符的控件,如表格,面板,标签或HTML控件,如表格,div或跨度元素,其runat属性设置为“server”。 项目模板是主要模板,它将以重复的方式显示与ListView绑定的数据。该模板通常包含数据绑定到数据列或其他单个数据元素的控件。这两个模板是强制性的。

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

Structure of ListView

下面这使得差别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

0

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

ItemTemplate属性只适用于绑定到控件的数据项。 LayoutTempate允许您为其他一切定义布局。

假设您想要使用a来呈现您的数据。您LayoutTemplate模板将包含您的表定义跟单,空行与ID,然后在“itemPlaceHolder”

<tr id="itemPlaceHolder" runat="server" />

你的项目模板将定义你的S应该如何呈现。

+0

谢谢你......请看到我的编辑问题 – Mihir 2011-02-10 10:03:57