我用如下方式在gv_rowcreated里合并表头后
        int i;
        //if (e.Row.RowType == DataControlRowType.Header) {
         switch (e.Row.RowType){
             case DataControlRowType.Header:
                System.Drawing.Color bg_color = ColorConvert.colorHx16toRGB("#006699");
                System.Drawing.Color fore_color = System.Drawing.Color.White;
                //总表头                
                TableCellCollection tcHeader = e.Row.Cells;
                tcHeader.Clear();
                //第一行表头                
                tcHeader.Add(new TableHeaderCell());
                tcHeader[0].Text = "";
                //第一行表头                
                tcHeader.Add(new TableHeaderCell());
                tcHeader[1].Attributes.Add("colspan", "2");
                tcHeader[1].Text = "药品</th></tr><tr>";
                
                //第二行表头
                tcHeader.Add(new TableHeaderCell());
                tcHeader[2].Text = "科室信息";                tcHeader.Add(new TableHeaderCell());
                tcHeader[3].Text = "药品金额";
                tcHeader.Add(new TableHeaderCell());
                tcHeader[4].Text = "比例";
                for (i = 0; i < tcHeader.Count; i++)
                {
                    tcHeader[i].BackColor = bg_color;
                    tcHeader[i].ForeColor = fore_color;
                    tcHeader[i].Font.Bold = true;
                    tcHeader[i].Font.Size = 10;
                }
                //tcHeader.RemoveAt(0);
                break;
         }
想再隐藏gridview中的某列,比如
this.GridView1.column[0].visible=false,但是提示超出索引,是什么原因啊?
有什么解决方法没?

解决方案 »

  1.   

    我在网上找了段代码,好像可以
             if (e.Row.RowType == DataControlRowType.Header)
             {
                 e.Row.Cells[0].Style.Add("display", "none");
                 e.Row.Cells[2].Style.Add("display", "none");
             }
             if (e.Row.RowIndex > -1)
             {
                 if (e.Row.RowType == DataControlRowType.DataRow)
                 {
                     if (e.Row.RowType != DataControlRowType.Header)
                     {
                         e.Row.Cells[0].Style.Add("display", "none");
                         //e.Row.Cells[2].Style.Add("display", "none");
                     }             }
             }