asp.net - 项目模板和布局模板之间的区别

标签 asp.net data-binding

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

除了这个之外,我还在这样的项目中查询

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

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

谢谢

最佳答案

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

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 site , code project reference

关于asp.net - 项目模板和布局模板之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4955512/

相关文章:

asp.net - 服务器与开发环境上的 Unicode 字符串比较和 CType 差异

c# - 为什么写入class.cs文件时 'Request'这个名字不存在?

data-binding - 动态生成单选按钮的模型更新

asp.net - 从 ASP.NET 在 Facebook 中将 div 内容共享为图像

c# - 不同的模型从同一数据库的不同表中获取数据 ASP.NET MVC 4

c# - 从 WPF 中的数据绑定(bind)数据网格中排除列

wpf - 操作 ObservableCollection 与替换列表

c# - UWP 应用程序中的高级 MVVM 场景 - 如何将模型类用于多个 View 模型?

css - 为什么 Font-Size 和 CssClass 属性在 aspx 页面的 CheckBoxList 中不起作用?

android - 使用 Kotlin for Android 进行数据绑定(bind)的问题