It seems like there's no way to manipulate the columns of a Gridview if AutoGenerateColumns = true. Here's my scenario:
I've got a generic GridView that displays the results of various different LINQ queries depending upon what the user selects. I like the fact that the AutoGenerateColumns works like it should and I don't have to specify all the BoundField, TemplateField columns, etc...
On top of that, I'm also programatically adding other columns as needed. The columns that are programatically added are rendered to the left of the autogenerated columns. What if I wanted to move them to the right?
GridView.Columns.Count only counts those that are programmed, not autogenerated, so I can't rearrange the columns I want around. I can hook the RowDataBound event and "hide" something if necessary, but I can't rearrange.
Do I just have to give up AutoGeneratedColumns=true, and lay them out with BoundFields for each query? Is there anything I can do?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…