The DataGrid Controls for ASP.NET Ajax WebForms provides large flexibility to meet any critical requirements of applications nowadays. Furthermore, the web DataGrid View control also provides data presentation, data refresh, data entry, data analysis, codeless development and hardcore coding functionalities. By using the Data Grid Control for ASP.NET Web Forms, users can easily manage the data by reordering columns and rows with nice user interface of the Grid. It is really easy to reorder columns and rows while using the Data Gridview control in asp.net.
There are two ways to reorder grid columns. One is through C#/VB.NET code in programming, the other is through dragging and dropping the column items in run-time.
Reordering columns by programming code
After a web Grid view generated, the columns display in some order you set. However, sometimes there maybe some other demand on your grid view. For example, maybe the Date column is behind the PeopleName column original, but now we need change the Date column go ahead to the PeopleName column. If you want to reset the order of the columns, you can use methods below:
1. Using the OrderIndex property. You can reset each column index through this property. Then all the columns will be sorted if you defined the every index of grid column.
Some sample C# code:
2. Using SwapColumns() method. You can input the two columns' name or two columns' index to exchange these two. This API looks like more useful and convenient, you don't need change all the columns in the web grid, just the two you defined.
C# example code:
Reordering columns by dragging and dropping
Note, if you want to reorder column in this way, you need set ClientSettings.AllowColumnsReorder property to True.
Here, we will show you how to reorder the rows by dragging and dropping grid row items. Users can drag and drop one row by border handle to the wanted location to reorder these rows in the same grid. If you drag the sixth row to the second position, then the original second to fifth rows will automatically shift down. If you drag the third row to the eighth position, the original fourth to eighth rows will dynamically shift up.
In addition, Kettic asp.net ajax grid view control allows users to drag and drop one row from one grid to a different web grid in the same html page.
Before dragging and dropping, users need set AllowRowsDragDrop and AllowRowSelect property to True. See the ASPX code below:
ASP.NET AJAX UI Controls