Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Getting DataGrid Header information

Reply
Thread Tools

Getting DataGrid Header information

 
 
GaryDean
Guest
Posts: n/a
 
      10-08-2006
I am writing a method in a component that gets passed a 1.1 Datagrid. The
datagrid's columns were created at run time meaning it has no columns
collection.

How can I access Header and Footer data in the grid?

It's not in the grid.items collection - only rows there. there is no
grid.header or grid.footer.

--
Regards,
Gary Blakely


 
Reply With Quote
 
 
 
 
Cowboy \(Gregory A. Beamer\)
Guest
Posts: n/a
 
      10-08-2006
No, but there is a header row and a footer row and you can query row type.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************************************************
Think outside of the box!
*************************************************
"GaryDean" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I am writing a method in a component that gets passed a 1.1 Datagrid. The
>datagrid's columns were created at run time meaning it has no columns
>collection.
>
> How can I access Header and Footer data in the grid?
>
> It's not in the grid.items collection - only rows there. there is no
> grid.header or grid.footer.
>
> --
> Regards,
> Gary Blakely
>
>



 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlsb3N6IFNrYWxlY2tp?=
Guest
Posts: n/a
 
      10-08-2006
Hi Gary,

C#
MyGrid.Controls[0].Controls[0] ' header
MyGrid.Controls[0].Controls[MyGrid.Controls[0].Controls.Count - 1] ' footer

Vb.Net
MyGrid.Controls(0).Controls(0) ' header
MyGrid.Controls(0).Controls(MyGrid.Controls(0).Con trols.Count - 1) ' footer

Remeber to check if the ShowHeader and ShowFooter properties are set to true
before running the above code (plus the range check if
(MyGrid.Controls[0].Count > 0) ...

Hope this helps

--
Milosz Skalecki
MCP, MCAD


"GaryDean" wrote:

> I am writing a method in a component that gets passed a 1.1 Datagrid. The
> datagrid's columns were created at run time meaning it has no columns
> collection.
>
> How can I access Header and Footer data in the grid?
>
> It's not in the grid.items collection - only rows there. there is no
> grid.header or grid.footer.
>
> --
> Regards,
> Gary Blakely
>
>
>

 
Reply With Quote
 
GaryDean
Guest
Posts: n/a
 
      10-09-2006
Yes. that does it. Thanks much!

--
Regards,
Gary Blakely
"Milosz Skalecki" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Gary,
>
> C#
> MyGrid.Controls[0].Controls[0] ' header
> MyGrid.Controls[0].Controls[MyGrid.Controls[0].Controls.Count - 1] '
> footer
>
> Vb.Net
> MyGrid.Controls(0).Controls(0) ' header
> MyGrid.Controls(0).Controls(MyGrid.Controls(0).Con trols.Count - 1) '
> footer
>
> Remeber to check if the ShowHeader and ShowFooter properties are set to
> true
> before running the above code (plus the range check if
> (MyGrid.Controls[0].Count > 0) ...
>
> Hope this helps
>
> --
> Milosz Skalecki
> MCP, MCAD
>
>
> "GaryDean" wrote:
>
>> I am writing a method in a component that gets passed a 1.1 Datagrid.
>> The
>> datagrid's columns were created at run time meaning it has no columns
>> collection.
>>
>> How can I access Header and Footer data in the grid?
>>
>> It's not in the grid.items collection - only rows there. there is no
>> grid.header or grid.footer.
>>
>> --
>> Regards,
>> Gary Blakely
>>
>>
>>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      10-09-2006
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.

 
Reply With Quote
 
=?Utf-8?B?TWlsb3N6IFNrYWxlY2tp?=
Guest
Posts: n/a
 
      10-09-2006
Steven,

I agree with you but my answer is based on his post (datagrid, asp.net 1.1,
reference is passed - so i quess you cannot do it in proper way i.e. in
itemcreated)

Regards
--
Milosz Skalecki
MCP, MCAD


"Steven Cheng[MSFT]" wrote:

> 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.
>
>

 
Reply With Quote
 
GaryDean
Guest
Posts: n/a
 
      10-09-2006
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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      10-10-2006
Thanks for your followup Gary,

So I've got the point here that your helper method will accept both 1.1
DataGrid and 2.0 Gridview class instance. Thus, I agree that except
directly access the Controls collection, there is no other means to get
the header and footer control collection for 1.1 DataGrid.

Anyway, I still suggest you add more protection code (like check null
reference) in your code which access Header/Footer through index in
Controls collection.

Please feel free to let me know if there is anything else we can help.


Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Header files with "header.h" or <header.h> ?? mlt C++ 2 01-31-2009 02:54 PM
datagrid having row header and column header krishna.dwivedi@gmail.com ASP .Net Datagrid Control 0 07-13-2006 08:20 AM
Any way to reorder how a datagrid is drawn (header/footer/items vs.header/items/footer)? Henrik ASP .Net Datagrid Control 1 07-06-2006 12:23 AM
strange information from asp.net trace / getting performance information using WebRequest and StreamReader z. f. ASP .Net 0 02-03-2005 11:23 AM
Getting error adding an extra header to datagrid AMD Desktop ASP .Net 3 11-02-2004 09:09 PM



Advertisments