技术开发 频道

ASPxGridView的多表头功能实现技巧

  【IT168 技术】关于如何实现ASPxGridView的多表头功能,写了一个公共方法可供使用,调用时只许在绑定方法前面调用即可。

  代码如下:

  //调用该方法即可

  
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)

  {
0
相关文章