GridView自动编号与合并表头

来源:互联网 发布:网络和信息安全责任书 编辑:程序博客网 时间:2024/06/05 03:23
 
//GridView自动编号
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    
{
        
if (e.Row.RowType == DataControlRowType.DataRow)
        
{
            e.Row.Cells[
0].Text = (e.Row.DataItemIndex + 1).ToString();
        }

    }

 

 

 //合并表头
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    
{
        
switch (e.Row.RowType)
        
{
            
case DataControlRowType.Header:
                
//第一行表头
                TableCellCollection tcHeader = e.Row.Cells;
                tcHeader.Clear();
                tcHeader.Add(
new TableHeaderCell());
                tcHeader[
0].Attributes.Add("bgcolor""White");
                tcHeader[
0].Attributes.Add("colspan""4"); //跨Column
                
//tcHeader[0].Attributes.Add("align", "left");
                tcHeader[0].Text = "产品列表</th></tr><tr>";
                
break;
        }

    }
原创粉丝点击