How do I change the DataGrid column order programmatically?

S

Sudhanshu Thakur

I use a single datagrid to load several different types of data depending
upon some user driven criteria. The AutoGenerateColumns property for the
datagrid is set to true. I also dynamically add a hyperlink template column
from an user control using the LoadTemplate method (thanks Dino Esposito).
The problem is that the template column always appears before the
autogenerated columns. What I want is for the template column to appear as
column # 2, sandwiched between two bound columns.

Is there any way to control the column position of the template column when
AutoGenerateColumns is set to true? Adding bound columns programmatically
in the Page_Load and slipping the template columns in between the two bound
columns sound like too much work. I am hoping for simple property I can set
to manipulate the column order.

Thanks,
S. Thakur
 
A

Alvin Bruney

The column order is based on the selection clause of the sql statement,
change the order of the sql query. If you want to adjust the order of the
template column you are out of luck. Items in the column collection come
before autobound columns.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top