当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > .Net中生成二维的表格的代码

ASP.NET
Script:WINDOWS Script 枚举运行中进程
使用Flex结合Webservice完成域名查询
VSTS Team System 总算装好了。
用于部署数据库的 数据库初始化工具 xzSQLDeploy Tools V1.0 (for SQLServer) f...
一个将阿拉伯数字转换成中文大写的最简单算法
SCRIPT:使用Windows Script 关闭和打开指定程序
Script:使用WINDOWS脚本访问WEB SERVICES
asp.net连接Access数据库
VB中IIS Application发布可能出现的问题
VB打包后的安装问题
Nhibernate的数据分页技术(续)
使用API函数复制文件,可显示进度。
VB打包技巧
VB.NET实现DirectSound9 (9) 实现示波器
VB.NET 实现DirectSound9 (10) 均衡器
[水晶报表部署系列之一]轻松搞定水晶报表9.2打包
DataGrid 中双向排序的一种办法
利用System.EventHandler来实现两个窗体间的事件调用
多线程应用程序中调用窗体的一点心得
Smart Client之旅一:用B/S方式运行Exe应用程序

ASP.NET 中的 .Net中生成二维的表格的代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 86 ::
收藏到网摘: n/a

  找了很久才找到的在.NET中生成二维表格代码,不敢独享,现在就贴出来给大家看看,相信对大家有所帮助。

  代码如下:

  void Page_Load(object o, EventArgs e)
  ...{
  DataTable dt = GetData(); //assume GetData returns the DataTable
  //probably better to use Hashtable for depts and months too, but to keep the order, let’s use ArrayList
  string sSeparator = ":";
  ArrayList alDept = new ArrayList(); //种类
  ArrayList alMonth = new ArrayList(); //代码
  Hashtable ht = new Hashtable();
  foreach (DataRow dr in dt.Rows)
  ...{
  string sDept = dr["c"].ToString();
  string sMonth2 = dr["p"].ToString();
  //将产地代码转换为产地名称
  string sMonth = GetData2(sMonth2);
  if (!alDept.Contains(sDept))
  alDept.Add(sDept);
  if (!alMonth.Contains(sMonth))
  alMonth.Add(sMonth);
  ht[sDept+ sSeparator + sMonth] = dr["a"];
  }
  TableRow tr = new TableRow();
  TableCell tc = new TableCell();
  //tc.Text = " ";
  //tr.Cells.Add(tc);
  foreach (string sDept in alDept)
  ...{
  int i=0; //用于计算某一种类的数量
  foreach (string sMonth in alMonth)
  ...{
  if(ht[sDept+ sSeparator + sMonth]==null)
  ...{
  i=i+0;
  }
  else
  ...{
  i = i + int.Parse(ht[sDept+ sSeparator + sMonth].ToString());
  }
  }
  tc = new TableCell();
  tc.Text= sDept+"("+i+")";
  tr.Cells.Add(tc);
  }
  /**//*foreach (string sDept in alDept)
  {
  tc = new TableCell();
  tc.Text= sDept;
  tr.Cells.Add(tc);
  } */
  Table1.Rows.Add(tr);
  foreach (string sMonth in alMonth)
  ...{
  tr = new TableRow();
  /**//*tc = new TableCell();
  tc.Text = sMonth;
  tr.Cells.Add(tc);*/
  foreach (string sDept in alDept)
  ...{
  tc = new TableCell();
  if(ht[sDept+ sSeparator + sMonth]==null)
  ...{
  tc.Text=sMonth+"(0)";
  }
  else
  ...{
  tc.Text = sMonth+"("+ ht[sDept+ sSeparator + sMonth].ToString()+")";
  }
  tr.Cells.Add(tc);
  }
  Table1.Rows.Add(tr);
  }
  }
  Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
  override protected void OnInit(EventArgs e)
  ...{
  //
  // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
  //
  InitializeComponent();
  base.OnInit(e);
  }
  /**//// 
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// 
  private void InitializeComponent()
  ...{
  this.Load += new System.EventHandler(this.Page_Load);
  }
  #endregion
  public DataTable GetData()
  ...{
  StatisticsB stat=new StatisticsB();
  DataSet dataset=stat.byStone();
  return dataset.Tables["stat"];
  }
  //取得名称列表
  public string GetData2(string statid)
  ...{
  StatisticsB stat=new StatisticsB();
  return stat.changeToName(statid);
  }