GridView Header 分行

来源:互联网 发布:雅思网络课程百度云 编辑:程序博客网 时间:2024/06/05 22:38
gvGpsData.RowCreated += new GridViewRowEventHandler(gvGpsData_RowCreated);
        void gvGpsData_RowCreated(object sender, GridViewRowEventArgs e)        {            if (e.Row.RowType == DataControlRowType.Header)            {                TableCellCollection tcHeader = e.Row.Cells;                tcHeader.Clear();                //第一行表头                   GridViewRow rh0 = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);                TableCell hc = new TableCell();                hc.Text = "地区";                hc.RowSpan = 2;                rh0.Cells.Add(hc);                hc = new TableCell();                hc.Text = "班线客运及旅游客运";                hc.ColumnSpan = 6;                rh0.Cells.Add(hc);                hc = new TableCell();                hc.Text = "危险品运输";                hc.ColumnSpan = 6;                rh0.Cells.Add(hc);                hc = new TableCell();                hc.Text = "重载普货";                hc.ColumnSpan = 6;                rh0.Cells.Add(hc);                hc = new TableCell();                hc.Text = "合计";                hc.ColumnSpan = 6;                rh0.Cells.Add(hc);                rh0.Visible = true;                gvGpsData.Controls[0].Controls.AddAt(0, rh0);                //第二行表头                 GridViewRow rh1 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Normal);                //班线客运及旅游客运                TableCell hc1 = new TableCell();                hc1.Text = "总数";                rh1.Cells.Add(hc1);                hc1 = new TableCell();                hc1.Text = "上线数";                rh1.Cells.Add(hc1);                hc1 = new TableCell();                hc1.Text = "上线率";                rh1.Cells.Add(hc1);                hc1 = new TableCell();                hc1.Text = "未上线";                rh1.Cells.Add(hc1);                hc1 = new TableCell();                hc1.Text = "未入网";                rh1.Cells.Add(hc1);                hc1 = new TableCell();                hc1.Text = "北斗";                rh1.Cells.Add(hc1);                //危险品运输                hc1 = new TableCell();                hc1.Text = "总数";                rh1.Cells.Add(hc1);                hc1 = new TableCell();                hc1.Text = "上线数";                rh1.Cells.Add(hc1);                hc1 = new TableCell();                hc1.Text = "上线率";                rh1.Cells.Add(hc1);                hc1 = new TableCell();                hc1.Text = "未上线";                rh1.Cells.Add(hc1);                hc1 = new TableCell();                hc1.Text = "未入网";                rh1.Cells.Add(hc1);                hc1 = new TableCell();                hc1.Text = "北斗";                rh1.Cells.Add(hc1);                //重载普货                hc1 = new TableCell();                hc1.Text = "总数";                rh1.Cells.Add(hc1);                hc1 = new TableCell();                hc1.Text = "上线数";                rh1.Cells.Add(hc1);                hc1 = new TableCell();                hc1.Text = "上线率";                rh1.Cells.Add(hc1);                hc1 = new TableCell();                hc1.Text = "未上线";                rh1.Cells.Add(hc1);                hc1 = new TableCell();                hc1.Text = "未入网";                rh1.Cells.Add(hc1);                hc1 = new TableCell();                hc1.Text = "北斗";                rh1.Cells.Add(hc1);                //合计                hc1 = new TableCell();                hc1.Text = "总数";                rh1.Cells.Add(hc1);                hc1 = new TableCell();                hc1.Text = "上线数";                rh1.Cells.Add(hc1);                hc1 = new TableCell();                hc1.Text = "上线率";                rh1.Cells.Add(hc1);                hc1 = new TableCell();                hc1.Text = "未上线";                rh1.Cells.Add(hc1);                hc1 = new TableCell();                hc1.Text = "未入网";                rh1.Cells.Add(hc1);                hc1 = new TableCell();                hc1.Text = "北斗";                rh1.Cells.Add(hc1);                rh1.Visible = true;                gvGpsData.Controls[0].Controls.AddAt(1, rh1);            }        }

效果图:


0 0
原创粉丝点击