3

I have a simple Gridview with AutoGenerate on. I need to know how to access these columns, because the column count is always zero, even though they show in the page.

I found something about an "AutoGeneratingColumn" event, but that's for DataGrids and only gives access to one column at a time.

Basically i need this to group the rows, using agrinei's GridViewHelper.

What doesn't work:

DataBound event, PreRender event, RowCreated event (because i need all columns), and Load event.

4

3 に答える 3

3

Autogenerated columns do not show up in the Columns collection by design, as you discovered. I haven't tried this, but here's an article about subclassing the Gridview and making it add those autogenerated columns to the Columns collection. Might help you out.

于 2011-08-04T14:09:09.737 に答える
2

Along with patmortech's article, I suggest this article which might also be useful since you're using ASP.NET.

于 2013-02-14T17:48:02.137 に答える
0

USE this

    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
        }
    }
于 2014-01-29T09:00:04.390 に答える