2011-02-10 99 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