资源预览内容
第1页 / 共13页
第2页 / 共13页
第3页 / 共13页
第4页 / 共13页
第5页 / 共13页
第6页 / 共13页
第7页 / 共13页
第8页 / 共13页
第9页 / 共13页
第10页 / 共13页
亲,该文档总共13页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
此例子是基于c#的Asp.net 上网找了很多动态生成table例子,发现太简陋,笔者在此写一个完整版的.效果如下: 1.输入商品种类数,动态生成需要的行数,在每一个单元格可以填写相应的信息, 2.其中单价,和入库数量只能填写数字,金额是只读框(因为金额=商品数量*单价,用户没有必要填写) 3.当填写完整一行信息(商品名称,数量,金额),将会自动计算金额数. 文件结构如下图示: MerchandiseInfo.cs是商品的结构类. MerchandiseType.cs是商品类型的结果类. TableCellModle.cs 是技术重点,此类中有生成各种单元格(TableCell)的方法,for example: 具有下拉列表的单元格方法(CreateCellddl),生成列标题的单元格方法(C reateHeadCell)生成列标题的不同颜色单元格方法(CreateHeadCellColo r). AotuCreatTable.aspxcs是显示table的页面. 代码:MerchandiseInfo.cs using System; using System.Collections.Generic; using System.Text; public class MerchandiseInfo / 商品编号 private string m_ID; public string ID get return m_ID; set m_ID = value; / 商品名称 private string m_Name; public string Name get return m_Name; set m_Name = value; / 商品数量 private int m_Number; public int Number get return m_Number; set m_Number = value; / 商品分类 private string m_TID; public string TID get return m_TID; set m_TID = value; / 金额 private decimal m_Amount; / 金额 public decimal Amount get return m_Amount; set m_Amount = value; / 单价 private decimal m_Price; public decimal Price get return m_Price; set m_Price = value; / 备注 private string m_Remark; public string Remark get return m_Remark; set m_Remark = value; / 全赋值构造函数 public MerchandiseInfo(string pName, decimal pPrice, int pNumber, string pTID, decimal pAmount, string pRemark) m_Name = pName; m_TID = pTID; m_Amount = pAmount; m_Price = pPrice; m_Number = pNumber; m_Remark = pRemark; MerchandiseType.cs public class MerchandiseType / 商品类型名称 private string m_Name; public string Name get return m_Name; set m_Name = value; / 商品类型ID private string m_ID; public string ID get return m_ID; set m_ID = value; / 全参函数 public MerchandiseType(string pID, string pName) m_ID = pID; m_Name = pName; TableCellModle.cs / 列表的单元格类 public class TableCellModle private TableCell tablecell = new TableCell(); private TextBox textbox = new TextBox(); private HiddenField hiField; private DropDownList ddl; public TableCellModle() / 具有下拉列表的 public TableCell CreateCellddl(string tID, string tText, int tPoint, int twidth, int tHeight, int lwidth, int lHeight, ref IList MTypeList) ddl = new DropDownList(); ddl.DataSource = MTypeList; ddl.DataTextField = Name; ddl.DataValueField = ID; ddl.DataBind(); ddl.AutoPostBack = false; ddl.ID = tID ; ddl.Font.Size = FontUnit.Point(tPoint); ddl.Width = twidth; ddl.Height = tHeight; ddl.BorderWidth = 0; tablecell.Controls.Add(ddl); tablecell.Width = lwidth; tablecell.Height = lHeight; tablecell.BorderWidth = 1; return tablecell; / 创建题眉 public TableCell CreateHeadCell(string tID, string tText, int lwidth, int lHeight) textbox.ID = tID; textbox.Text = tText; textbox.Font.Size = FontUnit.Point(13); textbox.Width = 150; textbox.Height = 20; textbox.BorderWidth = 0; textbox.BackColor = System.Drawing.Color.Yellow; textbox.ReadOnly = true; tablecell.Controls.Add(textbox); tablecell.Width = lwidth; tablecell.Height = lHeight; tablecell.BorderWidth = 1; tablecell.VerticalAlign = VerticalAlign.Middle; tablecell.Font.Size = FontUnit.Point(13); tablecell.Font.Bold = true; tablecell.HorizontalAlign = HorizontalAlign.Center; tablecell.BorderColor = System.Drawing.Color.Black; tablecell.BackColor = System.Drawing.Color.Yellow; return tablecell; / 创建头Cell(可以改变颜色) public TableCell CreateHeadCellColor(string tID, string tText, int lwidth, int lHeight, System.Drawing.Color pColor) textbox.ID = tID; textbox.Text = tText; textbox.Font.Size = FontUnit.Point(13); textbox.Width = 150; textbox.Height = 20; textbox.BorderWidth = 0; textbox.BackColor = pColor; textbox.ReadOnly = tr
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号