469,635 Members | 1,824 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,635 developers. It's quick & easy.

Gridview Inside User Control - Cannot Change Column Header Text

2
Hi,
I have an ascx file with a gridview, and I need to change the header text of the gridview's column in the code-behind. Something like that:

foreach (DataControlField col in GridView1.Columns)
{
col.HeaderText = GetString(col.HeaderText);
}

However, no matter where I place that code, the header texts return to their original value, and that's what's being displayed.

What could be the reason for that? And how can it be solved?
Aug 13 '08 #1
1 1914
cloud255
427 Expert 256MB
col.HeaderText = GetString(col.HeaderText);
here, you are saying, HeaderText of x = HeaderText of x. unless that GetString function does something really strange (which i doubt) the column will always have the same header text...

As far as placing the code:

Create a property, like a collection of strings that will represent the header names. In the properties setter, call the code to change the column headers with the values supplied to the property.

I would then expose a public event which will allow you to pass a colleciton of type string. The user of the control then needs to override the event...
Aug 13 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Chris Millar | last post: by
6 posts views Thread by Nalaka | last post: by
4 posts views Thread by Nalaka | last post: by
2 posts views Thread by rufpirat | last post: by
7 posts views Thread by rote | last post: by
4 posts views Thread by Yin99 | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.