ASP.NET 2.0中合并 GridView 的表头单元格

<%...@PageLanguage="VB"%>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<scriptrunat="server">...
FunctionCreateDataSource()AsICollection
DimdtAsSystem.Data.DataTable
=NewSystem.Data.DataTable
DimdrAsSystem.Data.DataRow
dt.Columns.Add(NewSystem.Data.DataColumn(
"学生姓名",GetType(System.String)))
dt.Columns.Add(NewSystem.Data.DataColumn(
"语文",GetType(System.Decimal)))
dt.Columns.Add(NewSystem.Data.DataColumn(
"数学",GetType(System.Decimal)))
dt.Columns.Add(NewSystem.Data.DataColumn(
"英语",GetType(System.Decimal)))
DimiAsInteger
=0
Fori
=0To7
DimrdAsSystem.Random
=NewSystem.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)
Next
DimdvAsSystem.Data.DataView
=NewSystem.Data.DataView(dt)
Returndv
EndFunction

ProtectedSubPage_Load(ByValsenderAsObject,ByValeAsEventArgs)
IfNotIsPostBackThen
GridView1.BorderColor
=System.Drawing.Color.DarkOrange
GridView1.DataSource
=CreateDataSource()
GridView1.DataBind()
EndIf
EndSub

ProtectedSubGridView1_RowCreated(ByValsenderAsObject,ByValeAsGridViewRowEventArgs)
Ife.Row.RowType
=DataControlRowType.HeaderThen
DimrowHeaderAsGridViewRow
=NewGridViewRow(0,0,DataControlRowType.Header,DataControlRowState.Normal)
rowHeader.BackColor
=System.Drawing.Color.White
rowHeader.Font.Bold
=True
DimcellsAsTableCellCollection
=e.Row.Cells
DimheaderCellAsTableCell
=NewTableCell
headerCell.Text
=""
rowHeader.Cells.Add(headerCell)
headerCell
=NewTableCell
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)
EndIf
EndSub

ProtectedSubGridView1_RowDataBound(ByValsenderAsObject,ByValeAsGridViewRowEventArgs)
e.Row.Attributes.Add(
"style","background:#FFF")
EndSub

</script>

<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<title>合并GridView的表头单元格</title>
</head>
<body>
<formid="Form1"runat="server">
<asp:GridViewID="GridView1"runat="server"CellSpacing="1"CellPadding="3"
Font-Size
="12px"Width="300px"BackColor="orange"BorderWidth="0"
OnRowDataBound
="GridView1_RowDataBound"OnRowCreated="GridView1_RowCreated">
</asp:GridView>
</form>
</body>
</html>

你可能感兴趣的:(.net,asp.net,asp,vb,VB.NET)