While I ordinarily set AutoGenerateColumns = false on ASP.NET DataGrids, I finally found a pretty good use for them. I had a result set that was coming back with a variable number of columns all of which need to be display. I thought what a perfect use for the auto-generating columns but low and behold I discovered the documentation says:
Note Explicitly declared columns may be used in conjunction with auto-generated columns. When using both, explicitly declared columns will be rendered first, followed by the auto-generated columns. Auto-generated columns are not added to the Columns collection.
The hell kind of garbage is that?!?! Why aren't Auto-generated columns added to the Columns collection?!?!? Shouldn't they abide by the same rules other columns do? After all, aren't they just BoundColumn's? All I wanted to do was simply set the DataFormatString property on them. What an annoyance! Instead I had to check the number of columns in the IDataReader using the FieldCount property and then programmatically creating each column and set the format. But then what is the point of the AutoGenerateColumns property? Has anyone ever used it in a real world application? Oh well.....