问题
How can i arrange columns in asp.net gridview? i want to change 4 columns' location. ForExample:
column1 | column2 | column3 | column4 |
ChangeOrder()
column2 | column1 | column3 | column4 |
ChangeOrder()
column4 | column2 | column3 | column1 |
I want to move columns in Gridview.
回答1:
2 options from the top of my head:
Turn AutoGenerateColumns off and add the columns yourself, mapping them to what you want in the dataset and in the order you want them.
Change your SQL query to return the columns in the order that you want.
回答2:
I don't know if this is an option for you, but the Telerik RadGrid supports this. See this online demo for details.
回答3:
you can Remove column first and insert a new one at the remove index. such as
var columnToMove = myGridView.Columns[1];
myGridView.Columns.RemoveAt(1);
myGridView.Columns.Insert(0, columnToMove);
回答4:
Easy way:
Goto aspx page.
Click on smart-tag (>) of gridview.
Edit columns
Arrange column order in 'selected fields'
Hope it works..
来源:https://stackoverflow.com/questions/771688/how-can-i-arrange-columns-in-asp-net-gridview