Click here to Skip to main content
14,238,693 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have a grid which displays autogenerated columns.i want to change the order of columns before grid is binded.For example the order of columns which it by default fetches from database is Col1 col2 col3 etc...But i want to display it as Col2 col3 Col1.How can i do this? Also I want to combine two columns and show it as single column for ex.
col|col2 should be displayed as 'From col1 to col2' under a single column.
Member 9822231 26-Nov-13 7:27am
where is your query?
ZurdoDev 26-Nov-13 7:28am
Sounds like you do not want autogenerated columns. You should either change your sql or just add your columns instead of doing autogenerated.
pwavell 26-Nov-13 7:35am
select min(slno),max(slno),date from table1.
I want to display it as 'From min(slno) to max(slno)' as one single column but in front end.
pwavell 26-Nov-13 7:55am
i m binding my gridview based on three different conditions and each time it fetches different number of columns also some new columns are new it possible to add columns dynamically from code behind?
JoCodes 26-Nov-13 8:24am
You should consider not using autogenerated columns .Instead go for dynamically adding gridview columns since you want different columns based on conditions...
JoCodes 26-Nov-13 8:27am
Check this as a starter
BulletVictim 27-Nov-13 2:35am
The easiest way to change the column order I know of would be to change it in the SQL select statement that you use.
Combining the to columns would be something like select Col1 + Col2 AS ColCombine.
Prasannala 28-Nov-13 1:26am
To change column order before grid bind, BulletVictim is right easy way is changing sql query select 'From '+Col1+'to '+Col2as newCol from table1.You can change disply order of columns after binding also.
gridview.Columns["Col1"].DisplayIndex = gridview.Columns["Col2"].DisplayIndex;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100