在ASP.NET中如何合并单元格?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在ASP.NET中如何合并单元格?相关的知识,希望对你有一定的参考价值。
具体实现方法主要是通过rowspan和colspan,最初添加一个label控件,里面加一个table:
Label.Text = "<table border=\'1\'><tr bgcolor=\'#ABCDEF\'><td rowspan=2>类别</td><td rowspan=2>难度系数</td><td rowspan=2>课程名称</td><td rowspan=2>课程代码</td><td rowspan=2>学分</td><td colspan=3>总学时数</td><td colspan=8>按学期周课时分配</td></tr><tr bgcolor=\'#ABCDEF\'><td>理论</td><td>实验</td><td>实习</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td><td>七</td><td>八</td></tr></tr>";
接着是显示数据库中的内容(以下是主要代码):
while (drr.Read())
Label.Text += "<tr>";
Label.Text += "<td>" + drr["类别"] + "</td>";
Label.Text += "<td>" + drr["难度系数"] + "</td>";
Label.Text += "<td>" + drr["课程名称"] + "</td>";
Label.Text += "<td>" + drr["课程代码"] + "</td>";
Label.Text += "<td>" + drr["学分"] + "</td>";
Label.Text += "<td>" + drr["理论学时"] + "</td>";
Label.Text += "<td>" + drr["实验学时"] + "</td>";
Label.Text += "<td>" + drr["实习学时"] + "</td>";
······
Label.Text += "<tr>";
合并后效果:
参考技术A <%...@ Page Language="C#" AutoEventWireup="true" %> http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ... ICollection CreateDataSource() ... System.Data.DataTable dt = new System.Data.DataTable(); System.Data.DataRow dr; dt.Columns.Add(new System.Data.DataColumn("学生姓名", typeof(System.String))); dt.Columns.Add(new System.Data.DataColumn("语文", typeof(System.Decimal))); dt.Columns.Add(new System.Data.DataColumn("数学", typeof(System.Decimal))); dt.Columns.Add(new System.Data.DataColumn("英语", typeof(System.Decimal))); for (int i = 0; i < 8; i++) ... System.Random rd = new System.Random(Environment.TickCount * i); ; dr = dt.NewRow(); dr[0] = "学生" + i.ToString(); dr[1] = System.Math.Round(rd.NextDouble() * 100, 2); dr[2] = System.Math.Round(rd.NextDouble() * 100, 2); dr[3] = System.Math.Round(rd.NextDouble() * 100, 2); dt.Rows.Add(dr); System.Data.DataView dv = new System.Data.DataView(dt); return dv; protected void Page_Load(object sender, EventArgs e) ... if (!IsPostBack) ... GridView1.BorderColor = System.Drawing.Color.DarkOrange; GridView1.DataSource = CreateDataSource(); GridView1.DataBind(); protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) ... if (e.Row.RowType == DataControlRowType.Header) ... GridViewRow rowHeader = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal); rowHeader.BackColor = System.Drawing.Color.White; rowHeader.Font.Bold = true; TableCellCollection cells = e.Row.Cells; TableCell headerCell = new TableCell(); headerCell.Text = ""; rowHeader.Cells.Add(headerCell); headerCell = new TableCell(); headerCell.Text = "学生成绩"; headerCell.ColumnSpan = cells.Count - 1; headerCell.HorizontalAlign = HorizontalAlign.Center; rowHeader.Cells.Add(headerCell); rowHeader.Visible = true; GridView1.Controls[0].Controls.AddAt(0, rowHeader); protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) ... e.Row.Attributes.Add("style", "background:#FFF"); http://www.w3.org/1999/xhtml"> 合并GridView 的表头单元格采纳哦本回答被提问者采纳
以上是关于在ASP.NET中如何合并单元格?的主要内容,如果未能解决你的问题,请参考以下文章
asp.net中怎样将html table单元格的值怎么取出来