Get Column of DataGrid Web Control

L

Laurence

I want to get the column name of a datagrid control. But DataGrid.Columns
always return a collection of count 0.

Thanks for your help in advance.
 
L

Laurence

Hi Eliyahu,

I looked at it after databinding. I can get the data from the datagrid but
cannot get the header.

Let me speak more about my request:

I am developing a component to import data from a datagrid. My users also
want to get the headers of the datagrid. However I don't know how to get the
headers. The returned Columns always contain no data.
The DataGrid.AutoGenerateColumns is true by default. I think maybe this
caused my problem but I have to create the columns dynamically.
 
E

Eliyahu Goldin

Your guess is right. The following is taken from the MSDN:

The Columns collection contains explicitly declared columns that get
rendered in the DataGrid control.
Note Explicitly declared columns may be used in conjunction with
automatically generated columns. When using both, explicitly declared
columns will be rendered first, followed by the automatically generated
columns. Automatically generated columns are not added to the Columns
collection.
Eliyahu
 
E

Eliyahu Goldin

If you generate the columns automatically, you should be able to get their
names from your datasource.

Eliyahu
 
L

Laurence

Thank you.
But unfortunately I can't know the names from the datasource because I am
developing a class for other developers. I don't know what kind of data
source they may use.
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top