Tuesday, March 13, 2012

Should HeaderText change the behavior of a GridView?

I have a GridView control with a few columns declared directly in the aspx
file. I have found that if I remove the HeaderText property from all columns
that the GridView handles state completely differently than if any of the
columns has a value set for HeaderText. This sounds completely wrong to me.
Has anyone ever heard of this?

When no columns have a HeaderText, the GridView maintains columns similarly
to the old DataGrid. If I want to dynamically change the columns, I have to
do it after every postback, or else the grid reverts back to the way it was
originally declared in the designer.

When at least one column does have a HeaderText, I can change the columns in
the collection at any point and they will get retained across postbacks.
However, if I change the columns collection at any point, all of my
TemplateFields decalared in the designer get blanked out and render as empty.

Why does HeaderText have such a drastic affect on my GridView, and how can I
have columns with a HeaderText and not have my TemplateFields get emptied?Replied to this at Forums
http://forums.asp.net/thread/1576785.aspx
--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net
"Harry Keck" <HarryKeck@.discussions.microsoft.comwrote in message
news:7B8183F5-17DA-42B2-BDD7-4349E8F560FA@.microsoft.com...

Quote:

Originally Posted by

>I have a GridView control with a few columns declared directly in the aspx
file. I have found that if I remove the HeaderText property from all
columns
that the GridView handles state completely differently than if any of the
columns has a value set for HeaderText. This sounds completely wrong to
me.
Has anyone ever heard of this?
>
When no columns have a HeaderText, the GridView maintains columns
similarly
to the old DataGrid. If I want to dynamically change the columns, I have
to
do it after every postback, or else the grid reverts back to the way it
was
originally declared in the designer.
>
When at least one column does have a HeaderText, I can change the columns
in
the collection at any point and they will get retained across postbacks.
However, if I change the columns collection at any point, all of my
TemplateFields decalared in the designer get blanked out and render as
empty.
>
Why does HeaderText have such a drastic affect on my GridView, and how can
I
have columns with a HeaderText and not have my TemplateFields get emptied?

0 comments:

Post a Comment