熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

.Net中生成二維的表格的代碼

2022-06-13   來源: .NET編程 
找了很久才找到的在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 lets use ArrayList
string sSeparator = ":";
ArrayList alDept = new ArrayList(); //種類
ArrayList alMonth = new ArrayList(); //代碼
Hashtable ht = new Hashtable();
foreach (DataRow dr in dtRows)
{
string sDept = dr["c"]ToString();
string sMonth = dr["p"]ToString();
//將產地代碼轉換為產地名稱
string sMonth = GetData(sMonth);
if (!alDeptContains(sDept))
alDeptAdd(sDept);
if (!alMonthContains(sMonth))
alMonthAdd(sMonth);
ht[sDept+ sSeparator + sMonth] = dr["a"];
}
TableRow tr = new TableRow();
TableCell tc = new TableCell();
//tcText = " ";
//trCellsAdd(tc);
foreach (string sDept in alDept)
{
int i=; //用於計算某一種類的數量
foreach (string sMonth in alMonth)
{
if(ht[sDept+ sSeparator + sMonth]==null)
{
i=i+;
}
else
{
i = i + intParse(ht[sDept+ sSeparator + sMonth]ToString());
}
}
tc = new TableCell();
tcText= sDept+"("+i+")";
trCellsAdd(tc);
}
/**//*foreach (string sDept in alDept)
{
tc = new TableCell();
tcText= sDept;
trCellsAdd(tc);
} */
TableRowsAdd(tr);
foreach (string sMonth in alMonth)
{
tr = new TableRow();
/**//*tc = new TableCell();
tcText = sMonth;
trCellsAdd(tc);*/
foreach (string sDept in alDept)
{
tc = new TableCell();
if(ht[sDept+ sSeparator + sMonth]==null)
{
tcText=sMonth+"()";
}
else
{
tcText = sMonth+"("+ ht[sDept+ sSeparator + sMonth]ToString()+")";
}
trCellsAdd(tc);
}
TableRowsAdd(tr);
}
}
Web 窗體設計器生成的代碼#region Web 窗體設計器生成的代碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調用是 ASPNET Web 窗體設計器所必需的
//
InitializeComponent();
baseOnInit(e);
}
/**//// 
/// 設計器支持所需的方法 不要使用代碼編輯器修改
/// 此方法的內容
/// 
private void InitializeComponent()
{
thisLoad += new SystemEventHandler(thisPage_Load);
}
#endregion
public DataTable GetData()
{
StatisticsB stat=new StatisticsB();
DataSet dataset=statbyStone();
return datasetTables["stat"];
}
//取得名稱列表
public string GetData(string statid)
{
StatisticsB stat=new StatisticsB();
return statchangeToName(statid);
}


From:http://tw.wingwit.com/Article/program/net/201311/14449.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.