ASP.NET 2.0中合并 GridView 的表頭單元格
系統(tǒng)
2515 0
<%
...
@PageLanguage
=
"
VB
"
%>
<!
DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<
script
runat
="server"
>
...
FunctionCreateDataSource()AsICollection
DimdtAsSystem.Data.DataTable
=
NewSystem.Data.DataTable
DimdrAsSystem.Data.DataRow
dt.Columns.Add(NewSystem.Data.DataColumn(
"
學(xué)生姓名
"
,GetType(System.String)))
dt.Columns.Add(NewSystem.Data.DataColumn(
"
語(yǔ)文
"
,GetType(System.Decimal)))
dt.Columns.Add(NewSystem.Data.DataColumn(
"
數(shù)學(xué)
"
,GetType(System.Decimal)))
dt.Columns.Add(NewSystem.Data.DataColumn(
"
英語(yǔ)
"
,GetType(System.Decimal)))
DimiAsInteger
=
0
Fori
=
0
To
7
DimrdAsSystem.Random
=
NewSystem.Random(Environment.TickCount
*
i)
dr
=
dt.NewRow
dr(
0
)
=
"
學(xué)生
"
+
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
=
"
學(xué)生成績(jī)
"
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
>
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
<
head
>
<
title
>
合并GridView的表頭單元格
</
title
>
</
head
>
<
body
>
<
form
id
="Form1"
runat
="server"
>
<
asp:GridView
ID
="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
>
ASP.NET 2.0中合并 GridView 的表頭單元格
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元