How can i arrange columns in asp.net gridview?

梦想与她 提交于 2019-12-24 08:23:01

问题


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:

  1. Turn AutoGenerateColumns off and add the columns yourself, mapping them to what you want in the dataset and in the order you want them.

  2. 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:

  1. Goto aspx page.

  2. Click on smart-tag (>) of gridview.

  3. Edit columns

  4. Arrange column order in 'selected fields'

Hope it works..



来源:https://stackoverflow.com/questions/771688/how-can-i-arrange-columns-in-asp-net-gridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!