all groups > asp.net datagrid control > september 2003 >
You're in the

asp.net datagrid control

group:

iterate through bound columns


iterate through bound columns Jim Corey
9/26/2003 2:26:58 PM
asp.net datagrid control:
Hello,

I have several pages with datagrids, and I was thinking of writing a common
excel function.

I want to iterate through the columns of each datagrid to pick off the
headings and data column names.

The datagrids may include template columns, so if I do this:

dim bc as BoundColumn
for each bc in myGrid.Columns
...

it'll raise an error when it hits the template column.

I saw a post about going through the items collection of the datagrid, but I
wasn't sure how
to do this.

JC



iterate through bound columns Svetlin Grancharov
9/28/2003 1:28:58 AM
Use DataGridColumn instead of BoundColumn. So the code
should be:

dim bc as DataGridColumn
for each bc in myGrid.Columns
...
After that depends on column (some could be BoundColumn,
some TemplateColumn) you can read headings and data column
names.

Svetlin Grancharov

[quoted text, click to view]
Re: iterate through bound columns jhcorey NO[at]SPAM yahoo.com
9/29/2003 6:53:43 AM
Well at this point I don't know how to figure out what kind of column bc is.
Do I use bc.GetType?
Any example appreciated.

[quoted text, click to view]
Re: iterate through bound columns Svetlin Grancharov
9/30/2003 2:43:32 AM
Yes you can use GetType().ToString() and after that to
look in this string but better is would be:
....
Dim dgc As DataGridColumn
Dim bc As ButtonColumn
dim tc as TemplateColumn
....
For Each dgc In myGrid.Columns
If TypeOf dgc Is ButtonColumn Then
bc = dgc
...
end if
...
If TypeOf dgc Is TemplateColumn Then
tc = dgc
...
end if
...
Next


Best

Svetlin Grancharov

[quoted text, click to view]
AddThis Social Bookmark Button