GridView控件 - 遍历多个标题行 [英] Gridview - Loop through multiple header rows

查看:437
本文介绍了GridView控件 - 遍历多个标题行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个控制台应用程序,是动态创建一个GridView。

 的GridView GV =新的GridView();
        gv.AutoGenerateColumns = FALSE;
        的for(int i = 0; I< dt.Columns.Count;我++)
        {
            绑定列绑定列=新的BoundField();
            boundfield.DataField = dt.Columns [I] .ColumnName.ToString();
            boundfield.HeaderText =改编[I]的ToString(); // dt.Columns [I] .ColumnName.ToString();
            gv.Columns.Add(绑定列);
        }

然后,两个标题行添加。下面是部分一排的:

  GridViewRow HeaderGridRow =新GridViewRow(0,0,DataControlRowType.Header,DataControlRowState.Insert);
        TableCell的HeaderCell =新的TableCell();        HeaderCell.Text =;
        HeaderCell.ColumnSpan = 4;
        HeaderGridRow.Cells.Add(HeaderCell);        //添加了更多的标题单元格,然后另一行这里        gv.DataSource = DT;
        gv.DataBind();        gv.Controls [0] .Controls.AddAt(0,HeaderGridRow);

使用的foreach 循环,在头调整独立单元格边框没有完成:

 的foreach(在gv.Rows GridViewRow行)
        {
            的TableCell T细胞= row.Cells [0];
            tCell.Attributes [风格] =BORDER-右:0;
        }

我一直试图找到一种方法,通过标题行中循环,并调整对细胞的一些边框。

使用的foreach(GridViewRow行gv.HeaderRow)试图,但 gv.HeaderRow 没有一个公共定义为的GetEnumerator

尝试的for(int i = 0; I< gv.HeaderRow.Cells.Count;我++)但这似乎并没有任何工作。

任何人有什么建议吗?

谢谢!


解决方案

试试这个

  GridViewRow headerRow = gv.HeaderRow;
的TableCell HCELL = headerRow.Cells [0];
hCell.Attributes [风格] =BORDER-右:0;

希望它能帮助

In a console app, a gridview is created dynamically.

        GridView gv = new GridView();
        gv.AutoGenerateColumns = false;
        for (int i = 0; i < dt.Columns.Count; i++)
        {
            BoundField boundfield = new BoundField();
            boundfield.DataField = dt.Columns[i].ColumnName.ToString();
            boundfield.HeaderText = arr[i].ToString();// dt.Columns[i].ColumnName.ToString();
            gv.Columns.Add(boundfield);
        }

Then, two more header rows are added. Here is a partial of one row:

        GridViewRow HeaderGridRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
        TableCell HeaderCell = new TableCell();

        HeaderCell.Text = "";
        HeaderCell.ColumnSpan = 4;
        HeaderGridRow.Cells.Add(HeaderCell);

        //more header cells added then another row here

        gv.DataSource = dt;
        gv.DataBind();

        gv.Controls[0].Controls.AddAt(0, HeaderGridRow);

Using a foreach loop, adjusting separate cell borders not in the header is done:

        foreach (GridViewRow row in gv.Rows)
        {               
            TableCell tCell = row.Cells[0];
            tCell.Attributes["style"] = "border-right:0";               
        }

I have been trying to find a way to loop through the header rows and adjust some borders on the cells.

Tried using foreach (GridViewRow row in gv.HeaderRow) but gv.HeaderRow does not have a public definition for GetEnumerator.

Tried for(int i = 0; i < gv.HeaderRow.Cells.Count; i++) but that doesn't seem to work either.

Anyone have any suggestions?

Thanks!!

解决方案

Try this

GridViewRow headerRow = gv.HeaderRow;            
TableCell hCell = headerRow.Cells[0];
hCell.Attributes["style"] = "border-right:0";               

Hope it helps

这篇关于GridView控件 - 遍历多个标题行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆