我有一个带有 AutoGenerate 的简单 Gridview。我需要知道如何访问这些列,因为列数始终为零,即使它们显示在页面中。
我发现了一些关于“AutoGeneratingColumn”事件的信息,但那是针对 DataGrids 的,一次只能访问一列。
基本上我需要这个来对行进行分组,使用 agrinei 的 GridViewHelper。
什么不起作用:
DataBound事件、PreRender事件、RowCreated事件(因为我需要所有列)和Load事件。
我有一个带有 AutoGenerate 的简单 Gridview。我需要知道如何访问这些列,因为列数始终为零,即使它们显示在页面中。
我发现了一些关于“AutoGeneratingColumn”事件的信息,但那是针对 DataGrids 的,一次只能访问一列。
基本上我需要这个来对行进行分组,使用 agrinei 的 GridViewHelper。
什么不起作用:
DataBound事件、PreRender事件、RowCreated事件(因为我需要所有列)和Load事件。
正如您所发现的,自动生成的列不会按设计显示在 Columns 集合中。我还没有尝试过,但这里有一篇关于子类化 Gridview并使其将这些自动生成的列添加到 Columns 集合的文章。可能会帮到你。
连同 patmortech 的文章,我推荐这篇文章,因为您使用的是 ASP.NET,所以它可能也很有用。
用这个
Table table = new Table();
table.GridLines = GridView1.GridLines;
table.Rows.Add(GridView1.HeaderRow);
foreach (GridViewRow gvr in GridView1.Rows)
{
table.Rows.Add(gvr);
}
for (int iRows = 0; iRows < table.Rows.Count; iRows++)
{
for (int iCells = 0; iCells < table.Rows[iRows].Cells.Count; iCells++)
{
//code here
}
}