Gridview表頭(跨行、跨列)顯示樣式!

iDotNetSpace發表於2009-04-23

下面就是實現這個的程式碼:

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            TableCellCollection tcHeader = e.Row.Cells;
            tcHeader.Clear();//原有表頭清空

            tcHeader.Add(new TableHeaderCell());
            tcHeader[0].Attributes.Add("rowspan", "2");               
            tcHeader[0].Text = "縣(市)、區";
            tcHeader[0].Width = 130;

            tcHeader.Add(new TableHeaderCell());
            tcHeader[1].Attributes.Add("rowspan", "2");            
            tcHeader[1].Text = "合計";
            tcHeader[1].Width = 30;

            tcHeader.Add(new TableHeaderCell());
            tcHeader[2].Attributes.Add("colspan", "2");   
            tcHeader[2].Text = "新生兒情況";
            tcHeader[2].Width = 100;

            tcHeader.Add(new TableHeaderCell());
            tcHeader[3].Attributes.Add("colspan", "3");   
            tcHeader[3].Text = "新生兒性別";
            tcHeader[3].Width = 100;

            tcHeader.Add(new TableHeaderCell());
            tcHeader[4].Attributes.Add("colspan", "2");   
            tcHeader[4].Text = "生育證";

            tcHeader.Add(new TableHeaderCell());
            tcHeader[5].Attributes.Add("colspan", "2");  
            tcHeader[5].Text = "出生醫學證明";
            tcHeader[5].Width = 130;

            tcHeader.Add(new TableHeaderCell());
            tcHeader[6].Attributes.Add("rowspan", "2");   
            tcHeader[6].Text = "備註";

            tcHeader.Add(new TableHeaderCell());
            tcHeader[7].Text = "活產";
            tcHeader[7].Width = 60;

            tcHeader.Add(new TableHeaderCell());
            tcHeader[8].Text = "死產";
            tcHeader[8].Width = 60;

            tcHeader.Add(new TableHeaderCell());
            tcHeader[9].Text = "男";
            tcHeader[9].Width = 60;

            tcHeader.Add(new TableHeaderCell());
            tcHeader[10].Text = "女";
            tcHeader[10].Width = 60;

            tcHeader.Add(new TableHeaderCell());
            tcHeader[11].Text = "性別比";
            tcHeader[11].Width = 60;

            tcHeader.Add(new TableHeaderCell());
            tcHeader[12].Text = "有";
            tcHeader[12].Width = 60;

            tcHeader.Add(new TableHeaderCell());
            tcHeader[13].Text = "無";
            tcHeader[13].Width = 60;

            tcHeader.Add(new TableHeaderCell());
            tcHeader[14].Text = "已辦理";
            tcHeader[14].Width = 60;

            tcHeader.Add(new TableHeaderCell());
            tcHeader[15].Text = "未辦理";
            tcHeader[15].Width = 60;
        }
    }

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-591576/,如需轉載,請註明出處,否則將追究法律責任。

下一篇: C#字串學習筆記
Gridview表頭(跨行、跨列)顯示樣式!
請登入後發表評論 登入
全部評論

相關文章