Reorder gridview's columns
-
I try to reorder column of a gridview by overriding CreateColumns. The problem is after i reorder the column, the result table is not correct. The data that is bound into the result table doesn't arrange as i aspect, only the header is. Here is the example .- no reorder H1 H2 H3 D11 D12 D13 D12 D 22 D23 reorder column H2 H3 H1 D11 D12 D13 D12 D 22 D23 why is it ?
-
I try to reorder column of a gridview by overriding CreateColumns. The problem is after i reorder the column, the result table is not correct. The data that is bound into the result table doesn't arrange as i aspect, only the header is. Here is the example .- no reorder H1 H2 H3 D11 D12 D13 D12 D 22 D23 reorder column H2 H3 H1 D11 D12 D13 D12 D 22 D23 why is it ?
Assuming the GridView control have more than 2 fields, the sample code below changes the order of the first two colomns:
protected override ICollection CreateColumns(PagedDataSource dataSource, bool useDataSource)
{
ICollection collection = base.CreateColumns(dataSource, useDataSource);DataControlField\[\] array = new DataControlField\[collection.Count\]; collection.CopyTo(array, 0); DataControlField tempField = array\[0\]; array\[0\] = array\[1\]; array\[1\] = tempField; return array;
}
-
Assuming the GridView control have more than 2 fields, the sample code below changes the order of the first two colomns:
protected override ICollection CreateColumns(PagedDataSource dataSource, bool useDataSource)
{
ICollection collection = base.CreateColumns(dataSource, useDataSource);DataControlField\[\] array = new DataControlField\[collection.Count\]; collection.CopyTo(array, 0); DataControlField tempField = array\[0\]; array\[0\] = array\[1\]; array\[1\] = tempField; return array;
}
Nope, this would not work at all; at least for my code. As I said on my question, i can reorder all the columns as expect, and i check that the ICollection that return from the CreateColumns is correct. But however, the data that is bound to the table is not correct. Actually, i already have the solution. I would post here if someone interest.
-
Nope, this would not work at all; at least for my code. As I said on my question, i can reorder all the columns as expect, and i check that the ICollection that return from the CreateColumns is correct. But however, the data that is bound to the table is not correct. Actually, i already have the solution. I would post here if someone interest.
Tee+ wrote:
Nope, this would not work at all; at least for my code
Not sure what you do with your custom control, but it does work in my case when I simply declare 3 fields in the exGridView control and use a sqldatasource to feed data. Anyway, glad you solved your problem.
-
Tee+ wrote:
Nope, this would not work at all; at least for my code
Not sure what you do with your custom control, but it does work in my case when I simply declare 3 fields in the exGridView control and use a sqldatasource to feed data. Anyway, glad you solved your problem.
Oh yeah, this might be the cause. I use ObjectDataSource. And i think the GridView do a early bound and cache it something like [ColumnIndex, Value]. Therefore, even if i reorder all columns, but when doing a actual binding The grdiview doesn't use the datafield in each column to retrieve the data, but use the cache data and the column index. -- modified at 10:31 Saturday 19th August, 2006