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.

WoF_Angel
  • 2,569
  • 9
  • 35
  • 54
  • The columns may be blank but are the rows also blank? Are you looking for the columns specifically (like the names of the columns) or just the data contained in the rows? – Gage Aug 04 '11 at 13:01

2 Answers2

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.

patmortech
  • 10,139
  • 5
  • 38
  • 50
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
        }
    }