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

ASP.NET
Active Directory 对象的控制
在vb中动态加载水晶报表rpt文件的方法
webconfig中进行登陆的权限、修改2
DataGrid(WinForm)显示行号最简单的方法
在EXCEL中获取列中不重复的值的个数
使用Visual C#制作可伸缩个性化窗体
关于控件注册和使用许可问题的解决办法
获取闭合符号中的字符串
判断点与多边形的状态(位置)
NHibernate初试
GetTickCount()函数精确到多少毫秒
VB.net中HOOK的应用(一)
C# to VB.Net translator..
用Visual C#调用Windows API函数
用API函数实现切换VCD的左右声道
元数据--自定义属性(VB.NET)
初学VB.NET连接SQL数据库
简单的DataGrid多表头制作方法
带输出参数的存储过程的使用及在C#中调用问题
VS的控件真是不好用,好不容易才搞定DataGrid

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 80 ::
收藏到网摘: 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);
  }