Hi Steven,
A couple years ago I wrote a component called PrintGrid
(
http://www.deanblakely.com/PrintGrid.aspx). The component creates a
Crystal Report of any DataGrid. It worked for the 1.1 DataGrid but I wrote
it using the Columns collection (my mistake) so it would not work for
columns created at run time. I have given it away to several hunderd
developers that are probably still using it.
Now I am improving the component by (1) converting it so it will work for
columns created at run time for the DataGrid and (2) work for the new 2.0
GridView. All the developer has to do is call a method in my component,
passing either a DataGrid or a GridView object to print a report.
So, I understand that you are suggesting that using the controls collection
may not be a safe thing to do. Ok, but what is my alternative? How can I
get the Header and Footer text without using the Columns Collection and
without using the Controls Collection for the 1.1 DataGrid?
Later, when I'm working on the GridView it looks like it will be easier
since there are the two properties you mention. But, PrintGrid must provide
functionality for the 1.1 DataGrid for a long time because it will be used
for a long time.
--
Regards,
Gary Blakely
"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:bf**************@TK2MSFTNGXA01.phx.gbl...
Hi Gary,
Milosz's suggestion is directly access the DataGrid's Controls collection
to retrieve the Header and Footer child control, this does work though it
require us to have clear view of the DataGrid's control tree (you can
view
page's control tree by turn on the page's output trace). However, I would
still recommend that we avoid this as much as possible since accessing
child control through index only is dangerous which may break between
different version changes.
BTW, are you using the DataGrid in ASP.NET 1.1 application or ASP.NET 2.0
application. If you're using it in ASP.NET 2.0 or plan to upgrade the
application to ASP.NET 2.0, you can consider the GridView control(specific
to ASP.NET 2.0) since it has naturally expose the "Footer" and "Header" as
two public properties (FooterRow and HeaderRow).
Please feel free to post here if you need any further help.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.