求!ASP.NET 单据开发,主、明细表功能实现
RT
功能效果如下
保存按钮 选择物品 增行 删行
表头
单据编号: 日期: XX
明细
序 物品名称 物品编号 数量 单价 合计金额
1 XX XXX 1 10.00 10.00
2 XX XX 2 8.00 16.00
跪求类似这样的单据功能实现
[解决办法]
给你写一个demo,你可以自己去修改。
首先,定义好数据实体模型,例如
public class Product
{
public string Name { get; set; }
public decimal Price { get; set; }
private DateTime _最后更新时间 = DateTime.Now;
public DateTime 最后更新时间
{
get { return _最后更新时间; }
set { _最后更新时间 = value; }
}
}
public class ProductOrder
{
public string ProductName { get; set; }
public DateTime DateTime { get; set; }
public string Address { get; set; }
public int Quantiy { get; set; }
public string Supplier { get; set; }
}
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
public static class BLL
{
private static List<Product> ProductDatabase = new List<Product>(){
new Product { Name="月亮美眉", Price=9009999},
new Product{ Name="屋子", Price=83722323},
new Product{ Name="一本书", Price=20}
};
public static IEnumerable<Product> GetProducts()
{
return ProductDatabase;
}
private static List<ProductOrder> ProductOrderDatabase = new List<ProductOrder>
{
new ProductOrder{ ProductName="月亮美眉", DateTime= DateTime.Now, Address="公主坟1号", Quantiy=100},
new ProductOrder{ ProductName="月亮美眉", DateTime= DateTime.Now.AddSeconds(12312), Address="公主坟2号", Quantiy=200, Supplier="天上人间"}
};
public static IEnumerable<ProductOrder> GetOrders(string productName)
{
return from x in ProductOrderDatabase
where x.ProductName == productName
select x;
}
<%@ Page Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html>
<script runat="server">
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
this.DetailsView1.Visible = true;
this.DetailsView1.DataBind();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>演示GridView+GridView</title>
</head>
<body>
<form id="form1" runat="server">
<table style="width: 100%">
<tr>
<td valign="top">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AutoGenerateSelectButton="True"
BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px"
CellPadding="4" DataKeyNames="Name" DataSourceID="ObjectDataSource1" ForeColor="Black"
GridLines="Vertical"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Name" HeaderText="名称" />
<asp:BoundField DataField="Price" HeaderText="售价" DataFormatString="{0:c}" HtmlEncode="False" />
</Columns>
<FooterStyle BackColor="#CCCC99" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#F7F7DE" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetProducts"
TypeName="BLL"></asp:ObjectDataSource>
</td>
<td valign="top">
<asp:GridView ID="DetailsView1" runat="server" AutoGenerateColumns="true" DataSourceID="ObjectDataSource2" Visible="false">
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" SelectMethod="GetOrders"
TypeName="BLL">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="ProductName" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
</td>
</tr>
</table>
<br />
</form>
</body>
</html>