Get Column of DataGrid Web Control

  • Thread starter Thread starter Laurence
  • Start date Start date
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.
 
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.
 
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
 
If you generate the columns automatically, you should be able to get their
names from your datasource.

Eliyahu
 
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

Back
Top