![](/img/trans.png)
[英]How to loop through the whole gridview rows including the rows in other pages?
[英]Gridview - Loop through multiple header rows
在控制台应用程序中,gridview是动态创建的。
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);
}
然后,再添加两个标题行。 这是一行的一部分:
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);
使用foreach
循环,可以调整标头中未包含的单独单元格边界:
foreach (GridViewRow row in gv.Rows)
{
TableCell tCell = row.Cells[0];
tCell.Attributes["style"] = "border-right:0";
}
我一直在尝试寻找一种方法来遍历标题行并调整单元格上的某些边框。
使用foreach (GridViewRow row in gv.HeaderRow)
但gv.HeaderRow
没有GetEnumerator
的公共定义。
尝试for(int i = 0; i < gv.HeaderRow.Cells.Count; i++)
但这似乎也不起作用。
有人有什么建议吗?
谢谢!!
尝试这个
GridViewRow headerRow = gv.HeaderRow;
TableCell hCell = headerRow.Cells[0];
hCell.Attributes["style"] = "border-right:0";
希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.