代码如下:
复制代码 代码如下:
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);
}