开发者

Accessing all of the columns of an AutoGenerated GridView - ASP.NET

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), an开发者_JAVA百科d Load event.


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.


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


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
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜