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.
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的文章一起,我建议这篇文章也可能因为你使用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
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.