//
调用该方法即可
public
static
void
SetAspxGridViewBand(DevExpress.Web.ASPxGridView.ASPxGridView gridView)
{
gridView.HtmlRowCreated
+=
new
DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventHandler(GridView1_HtmlRowCreated);
}
static
void
GridView1_HtmlRowCreated(
object
sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs e)
{
DevExpress.Web.ASPxGridView.ASPxGridView gridView
=
sender
as
DevExpress.Web.ASPxGridView.ASPxGridView;
///
/if the first data row has been added
if
(e.RowType
==
DevExpress.Web.ASPxGridView.GridViewRowType.Data
&&
e.VisibleIndex
==
gridView.PageIndex
*
gridView.SettingsPager.PageSize)
{
Table table
=
e.Row.Parent
as
Table;
if
(table
!=
null
)
{
TableRow row
=
new
TableRow();
TableCell firstBand
=
GetNewTableCell(row,
string
.Empty);
foreach
(DevExpress.Web.ASPxGridView.GridViewDataColumn col
in
gridView.Columns)
{
if
(col.FieldName.IndexOf(
"
|
"
)
>
0
)
{
string
bandname
=
col.FieldName.Substring(
0
, col.FieldName.IndexOf(
"
|
"
));
TableCell band
=
null
;
foreach
(TableCell t
in
row.Cells)
{
if
(t.Text
==
bandname)
{
band
=
t;
break
;
}
}
if
(band
==
null
)
{
band
=
GetNewTableCell(row, bandname);
}
col.Caption
=
col.FieldName.Substring(col.FieldName.IndexOf(
"
|
"
)
+
1
);
band.ColumnSpan
++
;
}
else
{
firstBand.ColumnSpan
++
;
}
}
table.Rows.AddAt(
0
, row);
}
}
}
//
可以在此修改单元格样式
private
static
TableCell GetNewTableCell(TableRow row,
string
bandname)
{
TableCell band
=
new
TableCell();
band.Text
=
bandname;
row.Cells.Add(band);
band.CssClass
=
"
dxgvHeader
"
;
band.HorizontalAlign
=
HorizontalAlign.Center;
band.BorderStyle
=
BorderStyle.NotSet;
band.BorderColor
=
row.BorderColor;
return
band;
}