如何将列添加到ASP.net ListView?

编程入门 行业动态 更新时间:2024-10-28 14:24:35
本文介绍了如何将列添加到ASP ListView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何将列添加到ASP ListView? <%@ Page 语言 = C# AutoEventWireup = true CodeBehind = Product.aspx.cs 继承 = ListViewProduct.Product %> < ! DOCTYPE html > < html xmlns = http:// www。 w3/1999/xhtml\"> < head runat = 服务器 > < link href = Content / bootstrap.css rel = 样式表 / > < link href = Content / bootstrap-theme.css rel = stylesheet / > < tit le > < / title > < / head > < 正文 > < 表格 id = form1 runat = 服务器 > < div > < asp:ListView ID = ListView1 runat = 服务器 SelectMethod = GetProducts ItemType = ListViewProduct.Product DataKeyNames = ProductID > < LayoutTemplate > < table class = table table-striped > < thead > < tr > < th > ProductName < / th > < th > UnitsInStock < / th > < th > UnitPrice < / th > < th > 新价格< / th > < th > TestTotalPrice < / th > < / tr > < / thead > < tbody > < ; tr id = itemPlaceholder runat = server > < / tr > < / tbody > < / table > < / LayoutTemplate > < ItemTemplate > < tr > < td > <% #Item。 ProductName %> < / td > < td > <%#Item.UnitsInStock %> ; < / td > < td > <%#Item.UnitPrice %> < / td > < td > <%#Item.NewPrice %> < / td > < td > <%#Item.TestTotalPrice %> < / td > < / tr > < / ItemTemplate > < / asp:ListView > < / div > < / form > < /正文 > < / html > namespace ListViewProduct { public partial class Product:System.Web.UI.Page { NorthwindEntities db = new NorthwindEntities(); protected void Page_Load(object sender,EventArgs e) { } public IEnumerable < 产品 > GetProducts() { return db.Products; } } } 名称空间ListViewProduct { using System; 使用System.Collections.Generic; 公共部分类产品 { public int ProductID {get;组; } public string ProductName {get;组; } public Nullable < int > SupplierID {get;组; } public Nullable < int > CategoryID {get;组; } public string QuantityPerUnit {get;组; } public Nullable < decimal > UnitPrice {get;组; } private Nullable < decimal > newPrice; public Nullable < decimal > NewPrice { get { if(UnitPrice> 80) { newPrice = UnitPrice * 0.9m; } 其他 { newPrice = UnitPrice; } 返回newPrice; } set {newPrice = value; } } // get {if(condition){return a; } else {return b;}} public Nullable < short > UnitsInStock {get;组; } public Nullable < short > UnitsOnOrder {get;组; } public Nullable < short > ReorderLevel {get;组; } public bool Discontinued {get;组; } public Nullable < decimal > TotalPrice {get;组; } // public Nullable < decimal > TestTotalPrice {get;组; } private Nullable < decimal > testTotalPrice; public Nullable < decimal > TestTotalPrice { get {return testTotalPrice; } set {testTotalPrice = UnitsInStock * UnitPrice; } } } }

解决方案

lvRegAnimals.Columns.Add( Id); lvRegAnimals.Columns.Add( 名称); lvRegAnimals.Columns.Add( 年龄);

How can I add column to ASP ListView? <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Product.aspx.cs" Inherits="ListViewProduct.Product" %> <!DOCTYPE html> <html xmlns="www.w3/1999/xhtml"> <head runat="server"> <link href="Content/bootstrap.css" rel="stylesheet" /> <link href="Content/bootstrap-theme.css" rel="stylesheet" /> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:ListView ID="ListView1" runat="server" SelectMethod="GetProducts" ItemType="ListViewProduct.Product" DataKeyNames="ProductID"> <LayoutTemplate> <table class="table table-striped"> <thead> <tr> <th>ProductName</th><th>UnitsInStock</th> <th>UnitPrice</th><th>New price</th><th>TestTotalPrice</th> </tr> </thead> <tbody> <tr id="itemPlaceholder" runat="server"></tr> </tbody> </table> </LayoutTemplate> <ItemTemplate> <tr> <td><%#Item.ProductName %></td> <td><%#Item.UnitsInStock %></td> <td><%#Item.UnitPrice %></td> <td><%#Item.NewPrice %></td> <td><%#Item.TestTotalPrice %></td> </tr> </ItemTemplate> </asp:ListView> </div> </form> </body> </html> namespace ListViewProduct { public partial class Product : System.Web.UI.Page { NorthwindEntities db = new NorthwindEntities(); protected void Page_Load(object sender, EventArgs e) { } public IEnumerable<Product> GetProducts() { return db.Products; } } } namespace ListViewProduct { using System; using System.Collections.Generic; public partial class Product { public int ProductID { get; set; } public string ProductName { get; set; } public Nullable<int> SupplierID { get; set; } public Nullable<int> CategoryID { get; set; } public string QuantityPerUnit { get; set; } public Nullable<decimal> UnitPrice { get; set; } private Nullable<decimal> newPrice ; public Nullable<decimal> NewPrice { get { if (UnitPrice > 80) { newPrice = UnitPrice * 0.9m; } else { newPrice = UnitPrice; } return newPrice; } set { newPrice = value; } } // get { if (condition) { return a; } else { return b;} } public Nullable<short> UnitsInStock { get; set; } public Nullable<short> UnitsOnOrder { get; set; } public Nullable<short> ReorderLevel { get; set; } public bool Discontinued { get; set; } public Nullable<decimal> TotalPrice { get; set; } //public Nullable<decimal> TestTotalPrice { get; set; } private Nullable<decimal> testTotalPrice; public Nullable<decimal> TestTotalPrice { get { return testTotalPrice; } set { testTotalPrice = UnitsInStock * UnitPrice; } } } }

解决方案

lvRegAnimals.Columns.Add("Id"); lvRegAnimals.Columns.Add("Name"); lvRegAnimals.Columns.Add("Age");

更多推荐

如何将列添加到ASP.net ListView?

本文发布于:2023-11-05 21:31:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1561913.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   ASP   ListView   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!