合并下单元格就行了:
http://www.cnblogs.com/singlepine/archive/2005/12/30/282990.html
http://www.cnblogs.com/singlepine/archive/2005/12/30/282990.html
解决方案 »
- Gridview里面加了模板列,用来显示进度条,为什么不能更改width
- asp.net中listview怎么用的??
- 如何获得当前鼠标的绝对位置?满足ie即可,鼠标移动,
- 只是一个IIS配置水印图片后,其它的页面素材图片显示不了
- 时间格式转换问题 最后10分了
- Crystal Report 10.2无法显示记录
- (帮顶有分)如何实现可编辑的下拉列表DropDownlist
- 模板列下如何使用金额显示XX,XXX.00的格式呀
- 100分,急需答案:系统管理员该做什么
- 如何用代码生成OleDbConnection.ConnectionString?
- 如何将在前台通过单击某按钮使Excel中的数据导入到sql server数据库中?
- 在DataTable怎样添加重复的列!!??
{
DataControlRowType elemType=e.Row.RowType;
if (e.Row.RowType == DataControlRowType.Header)
{
GridViewRow dgi = new GridViewRow(0, -1, DataControlRowType.Header, DataControlRowState.Normal);
GridViewRow dgi1 = new GridViewRow(0, -1, DataControlRowType.Header, DataControlRowState.Normal);
Table tb = new Table();
tb = (Table)GridView1.Controls[0];
tb.Rows.Clear();
tb.Rows.AddAt(0, dgi);
tb.Rows.AddAt(1, dgi1);
TableCell tc11 = new TableCell();
TableCell tc12 = new TableCell();
TableCell tc13 = new TableCell();
TableCell tc14 = new TableCell(); TableCell tc20 = new TableCell();
TableCell tc21 = new TableCell();
TableCell tc22 = new TableCell();
TableCell tc23 = new TableCell();
TableCell tc24 = new TableCell();
TableCell tc25 = new TableCell();
TableCell tc26 = new TableCell();
TableCell tc27 = new TableCell();
TableCell tc28 = new TableCell();
TableCell tc29 = new TableCell();
TableCell tc210 = new TableCell(); tc11.Text = "类别";
tc11.HorizontalAlign = HorizontalAlign.Center; /*tc11.RowSpan = 2;*/
dgi.Cells.Add(tc11);
tc12.Text = "温度(%)";
tc12.HorizontalAlign = HorizontalAlign.Center;
tc12.ColumnSpan = 5;
dgi.Cells.Add(tc12);
tc13.Text = "相对湿度(%)";
tc13.HorizontalAlign = HorizontalAlign.Center;
tc13.ColumnSpan = 5;
dgi.Cells.Add(tc13);
tc14.Text = "操作";
tc14.HorizontalAlign = HorizontalAlign.Center;
tc14.RowSpan = 2;
dgi.Cells.Add(tc14); tc20.Text = "日期";
tc20.HorizontalAlign = HorizontalAlign.Center;
dgi1.Cells.Add(tc20);
tc21.Text = "表一";
tc21.HorizontalAlign = HorizontalAlign.Center;
dgi1.Cells.Add(tc21);
tc22.Text = "表二";
tc22.HorizontalAlign = HorizontalAlign.Center;
dgi1.Cells.Add(tc22);
tc23.Text = "表三";
tc23.HorizontalAlign = HorizontalAlign.Center;
dgi1.Cells.Add(tc23);
tc24.Text = "表四";
tc24.HorizontalAlign = HorizontalAlign.Center;
dgi1.Cells.Add(tc24);
tc25.Text = "平均温度";
tc25.HorizontalAlign = HorizontalAlign.Center;
dgi1.Cells.Add(tc25);
tc26.Text = "表一";
tc26.HorizontalAlign = HorizontalAlign.Center;
dgi1.Cells.Add(tc26);
tc27.Text = "表二";
tc27.HorizontalAlign = HorizontalAlign.Center;
dgi1.Cells.Add(tc27);
tc28.Text = "表三";
tc28.HorizontalAlign = HorizontalAlign.Center;
dgi1.Cells.Add(tc28);
tc29.Text = "表四";
tc29.HorizontalAlign = HorizontalAlign.Center;
dgi1.Cells.Add(tc29);
tc210.Text = "平均湿度";
tc210.HorizontalAlign = HorizontalAlign.Center;
dgi1.Cells.Add(tc210); int nColumn = e.Row.Cells.Count;
for (int i = 0; i < nColumn; i++)
{
e.Row.Cells.RemoveAt(0);
}
} if (e.Row.RowType == DataControlRowType.Footer)
{
GridViewRow dgi2 = new GridViewRow(0, -1, DataControlRowType.Header, DataControlRowState.Normal);
Table tb = new Table();
tb = (Table)GridView1.Controls[0];
tb.Rows.AddAt(Convert.ToInt32(GridView1.Rows.Count)+3, dgi2);
TableCell tc11 = new TableCell();
TableCell tc12 = new TableCell();
TableCell tc21 = new TableCell();
TableCell tc22 = new TableCell(); tc11.Text = "平均温度";
tc11.ForeColor = Color.Black;
tc11.BackColor = Color.White;
tc11.HorizontalAlign = HorizontalAlign.Center;
dgi2.Cells.Add(tc11);
//计算平均温度
decimal Sum1=0;
decimal Statistic1 = 0;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
string temp = GridView1.Rows[i].Cells[5].Text.ToString();
if (temp == "")
temp = "0";
Sum1 += Convert.ToDecimal(temp);
Statistic1 = Sum1 / (i+1);
Statistic1 = decimal.Round(Statistic1, 2);
}
tc12.Text = Statistic1.ToString();
tc12.ForeColor = Color.Black;
tc12.BackColor = Color.White;
tc12.HorizontalAlign = HorizontalAlign.Center;
tc12.ColumnSpan = 5;
dgi2.Cells.Add(tc12); tc21.Text = "平均湿度";
tc21.ForeColor = Color.Black;
tc21.BackColor = Color.White;
tc21.HorizontalAlign = HorizontalAlign.Center;
dgi2.Cells.Add(tc21);
//计算平均湿度
decimal Sum2 = 0;
decimal Statistic2 = 0;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
string temp = GridView1.Rows[i].Cells[10].Text.ToString();
if (temp == "")
temp = "0";
Sum2 += Convert.ToDecimal(temp);
Statistic2 = Sum2 / (i + 1);
Statistic2 = decimal.Round(Statistic2, 2);
}
tc22.Text = Statistic2.ToString();
tc22.ForeColor = Color.Black;
tc22.BackColor = Color.White;
tc22.HorizontalAlign = HorizontalAlign.Center;
tc22.ColumnSpan = 5;
dgi2.Cells.Add(tc22); int nColumn = e.Row.Cells.Count;
for (int i = 0; i < nColumn; i++)
{
e.Row.Cells.RemoveAt(0);
}
}
}