close

需求的表頭是這樣

 

做法:

  protected void GV_RowCreated(object sender, GridViewRowEventArgs e)
        {//合併header

            if (e.Row.RowType == DataControlRowType.Header)
            {
                GridView gv = (GridView)sender;

                #region 第1列標題

                GridViewRow gvRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);

                // 增加 Department 欄位
                TableCell tc1 = new TableCell();
                tc1.Text = "總計月租費";
                tc1.ColumnSpan = 2;   // 跨兩欄
             
                tc1.Wrap = false;
                tc1.HorizontalAlign = HorizontalAlign.Center;
               

                gvRow.Cells.Add(tc1);

                // 增加 TOTAL SUM_ALL 欄位
                TableCell tc2 = new TableCell();
                tc2.Text = sum_all.ToString();
                tc2.ColumnSpan = 4;
        
                tc2.Wrap = false;
                tc2.HorizontalAlign = HorizontalAlign.Center;
                gvRow.Cells.Add(tc2);

                // 增加 異地Port數 欄位
                TableCell tc4 = new TableCell();
                tc4.Text = "異地Port數";//異地Port數
                tc4.ColumnSpan = 1;
                tc4.RowSpan = 3;
                tc4.Wrap = false;
                tc4.HorizontalAlign = HorizontalAlign.Center;
                gvRow.Cells.Add(tc4);
            
                // 增加Mirror Port數  欄位
                TableCell tc5 = new TableCell();
                tc5.Text = "Mirror Port數";//Mirror Port數
                tc5.ColumnSpan = 1;
                tc5.RowSpan = 3;
                tc5.Wrap = false;
                tc5.HorizontalAlign = HorizontalAlign.Center;
                gvRow.Cells.Add(tc5);

                // 增加 數位監控 欄位
                TableCell tc6 = new TableCell();
                tc6.Text = "數位監控";//數位監控
                tc6.ColumnSpan = 1;
                tc6.RowSpan = 3;
                tc6.Wrap = false;
                tc6.HorizontalAlign = HorizontalAlign.Center;
                gvRow.Cells.Add(tc6);


                // 增加 7*18維護費 欄位
                TableCell tc66 = new TableCell();
                tc66.Text = "7*18維護費";//數位監控
                tc66.ColumnSpan = 1;
                tc66.RowSpan = 3;
                tc66.Wrap = false;
                tc66.HorizontalAlign = HorizontalAlign.Center;
                gvRow.Cells.Add(tc66);


                // 增加 網路設備 欄位
                TableCell tc7 = new TableCell();
                tc7.Text = "網路設備";
                tc7.ColumnSpan = 5;
                tc7.Wrap = false;
                tc7.HorizontalAlign = HorizontalAlign.Center;
                gvRow.Cells.Add(tc7);
                // 增加 補/扣款金額 欄位
                TableCell tc8 = new TableCell();
                tc8.Text = "補扣款金額";//補扣款金額
                tc8.ColumnSpan = 1;
                tc8.RowSpan = 3;
                tc8.Wrap = false;
                tc8.HorizontalAlign = HorizontalAlign.Center;
                gvRow.Cells.Add(tc8);
                // 增加  月租費小計欄位
                TableCell tc9 = new TableCell();
                tc9.Text = "月租費小計";//月租費小計
                tc9.ColumnSpan = 1;
                tc9.RowSpan = 3;
                tc9.Wrap = false;
                tc9.HorizontalAlign = HorizontalAlign.Center;
                gvRow.Cells.Add(tc9);
                // 增加 備註 欄位
                TableCell tc10 = new TableCell();
                tc10.Text = "備註";//
                tc10.ColumnSpan = 1;
                tc10.RowSpan = 3;
                tc10.Wrap = false;
                tc10.HorizontalAlign = HorizontalAlign.Center;
                gvRow.Cells.Add(tc10);

                // 把這一列加到最上面
                gv.Controls[0].Controls.AddAt(0, gvRow);
                #endregion

                //*******************************************************************
                #region 第2列標題
                GridViewRow gvRow2 = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);

                // 增加 計費截止日 欄位
                TableCell tcs6 = new TableCell();
                tcs6.Text = "計費截止日";
                tcs6.ColumnSpan = 2;
                tcs6.Wrap = false;
                tcs6.HorizontalAlign = HorizontalAlign.Center;
                gvRow2.Cells.Add(tcs6);


                // 增加 dete 欄位
                TableCell tcs7 = new TableCell();
                tcs7.Text = FDATE.Text; ;
                tcs7.ColumnSpan = 4;
                tcs7.Wrap = false;
                tcs7.HorizontalAlign = HorizontalAlign.Center;
                gvRow2.Cells.Add(tcs7);


                // 增加 VOIP 欄位
                TableCell tcs8 = new TableCell();
                tcs8.Text = "VOIP";
                tcs8.ColumnSpan = 1;
                tcs8.Wrap = false;
                tcs8.HorizontalAlign = HorizontalAlign.Center;
                gvRow2.Cells.Add(tcs8);
                // 增加  Router欄位
                TableCell tcs9 = new TableCell();
                tcs9.Text = "Router";
                tcs9.ColumnSpan = 1;
                tcs9.Wrap = false;
                tcs9.HorizontalAlign = HorizontalAlign.Center;
                gvRow2.Cells.Add(tcs9);
                // 增加  欄位
                TableCell tcs10 = new TableCell();
                tcs10.Text = "網管系統";
                tcs10.ColumnSpan = 1;
                tcs10.Wrap = false;
                tcs10.HorizontalAlign = HorizontalAlign.Center;
                gvRow2.Cells.Add(tcs10);
                // 增加  欄位
                TableCell tcs11 = new TableCell();
                tcs11.Text = "UPS"; //400
                tcs11.ColumnSpan = 1;
                tcs11.Wrap = false;
                tcs11.HorizontalAlign = HorizontalAlign.Center;
                gvRow2.Cells.Add(tcs11);
                // 增加  欄位
                TableCell tcs12 = new TableCell();
                tcs12.Text = "機櫃"; //120
                tcs12.ColumnSpan = 1;
                tcs12.Wrap = false;
                tcs12.HorizontalAlign = HorizontalAlign.Center;
                gvRow2.Cells.Add(tcs12);

        

                gv.Controls[0].Controls.AddAt(1, gvRow2);

                #endregion

                //*******************************************************************
                #region 第3列標題

                GridViewRow gvRow3 = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);

                TableCell tct1 = new TableCell();
                tct1.Text = "序號";
                tct1.Wrap = false;
                tct1.HorizontalAlign = HorizontalAlign.Center;
                gvRow3.Cells.Add(tct1);
                TableCell tct1_1 = new TableCell();
                tct1_1.Text = "類別";
                tct1_1.Wrap = false;
                tct1_1.HorizontalAlign = HorizontalAlign.Center;
                gvRow3.Cells.Add(tct1_1);

                TableCell tct3 = new TableCell();
                tct3.Text = "店名";
                tct3.Wrap = false;
                tct3.HorizontalAlign = HorizontalAlign.Center;
                gvRow3.Cells.Add(tct3);

                TableCell tct2 = new TableCell();
                tct2.Text = "ATM機號";
                tct2.Wrap = false;
                tct2.HorizontalAlign = HorizontalAlign.Center;
                gvRow3.Cells.Add(tct2);

               

                TableCell tct4 = new TableCell();
                tct4.Text = "計費期間";
                tct4.Wrap = false;
                tct4.HorizontalAlign = HorizontalAlign.Center;
                gvRow3.Cells.Add(tct4);

                TableCell tct41 = new TableCell();
                tct41.Text = "計費天數";
                tct41.Wrap = false;
                tct41.HorizontalAlign = HorizontalAlign.Center;
                gvRow3.Cells.Add(tct41);


                 TableCell tct5 = new TableCell();
                tct5.Text = "160";
                tct5.Wrap = false;
                tct5.HorizontalAlign = HorizontalAlign.Center;
                gvRow3.Cells.Add(tct5);

                TableCell tct6 = new TableCell();
                tct6.Text = "1250";
                tct6.Wrap = false;
                tct6.HorizontalAlign = HorizontalAlign.Center;
                gvRow3.Cells.Add(tct6);

                TableCell tct7 = new TableCell();
                tct7.Text = "120";
                tct7.Wrap = false;
                tct7.HorizontalAlign = HorizontalAlign.Center;
                gvRow3.Cells.Add(tct7);


                TableCell tct8 = new TableCell();
                tct8.Text = "400";
                tct8.Wrap = false;
                tct8.HorizontalAlign = HorizontalAlign.Center;
                gvRow3.Cells.Add(tct8);

                TableCell tct9 = new TableCell();
                tct9.Text = "120";
                tct9.Wrap = false;
                tct9.HorizontalAlign = HorizontalAlign.Center;
                gvRow3.Cells.Add(tct9);

                gv.Controls[0].Controls.AddAt(2, gvRow3);
          

                #endregion

            }

        }

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 11 的頭像
    11

    冠霖的部落格

    11 發表在 痞客邦 留言(0) 人氣()