GridView中实现表头分层

    今天用GridView碰到一个问题,我的表头有几个字段跨了两行,有几个字段却只跨了一行。问题解决办法如下:
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            string strTitle = @"<tr><td rowspan = '2'>水源地名称</td>";  //rowspan为跨行数
            strTitle = strTitle + @"<td rowspan ='2'>水源地编码</td>";
            strTitle = strTitle + @"<td rowspan = '2'>输水方式</td>";
            strTitle = strTitle + @"<td rowspan = '2'>是否有调蓄设施</td>";
            strTitle = strTitle + @"<td rowspan ='2'>输水长度</td>";
            strTitle = strTitle + @"<td colspan ='6' align = 'center'>净水厂处理工艺</td></tr>"; //colspan为跨列数
            strTitle = strTitle + @" <td>沉淀</td>";
            strTitle = strTitle + @"<td>过滤</td>";
            strTitle = strTitle + @"<td>消毒</td>";
            strTitle = strTitle + @"<td>强化深度处理</td>";
            strTitle = strTitle + @"<td>含藻水特殊处理工艺</td>";
            strTitle = strTitle + @"<td>其他</td></tr>";

            TableCellCollection tcHeader = e.Row.Cells;
            tcHeader.Clear();
            tcHeader.Add(new TableCell());
            tcHeader[0].Text = strTitle;

        }
    }

posted @ 2009-07-28 14:27  kerry1986  阅读(440)  评论(0编辑  收藏  举报