Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Gridview HeaderText not changing

Posted on 2008-11-01
7
372 Views
Last Modified: 2011-08-18
Hello,

I have issue can't explain with a BulkEditGridView headers.

In design view I don't know what the headers will be...it changes depending on unit set in web.config.
So I leave the header as e.g.

<asp:TemplateField HeaderStyle-Font-Bold="false" HeaderText="ABC Input [UNIT]">

and populate on Page_Load correct headers on page_load like this
Me.Production.Columns(1).HeaderText = "ABC Input [metric unit]"

The headers aren't changing though on screen.

As a test I did in Page_Load before/after setting HeaderText:

System.Diagnostics.Debug.Print("Page_Load pre-setColumnTitles  HEADER: " & Me.Production.Columns(1).HeaderText())
Me.Production.Columns(1).HeaderText = "ABC Input [metric unit]"
System.Diagnostics.Debug.Print("Page_Load post-setColumnTitles HEADER: " & Me.Production.Columns(1).HeaderText())

the first debug line gives header as "ABC Input [UNIT]" - expected, this is what it is in design view
the next debug line gives header as "ABC Input [metric unit]" - expected, it has just been changed

HOWEVER, on the screen in browser the header says ABC Input [UNIT]  - it isn't changed.

Why would this be? This is the last bit of code on Page_Load

The BulkEditGridview is in a Menu_View. Interestingly if I go from the current view to another view and back again I find that the titles HAVE been changed

Thanks in advance for help on solving this
0
Comment
Question by:rwallacej
  • 4
  • 3
7 Comments
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22860308
did  AutoGenerateColumns="False" in your gridview .. if not please do that and bind your column and test
0
 

Author Comment

by:rwallacej
ID: 22865838
hi,
AutoGenerateColumns="False" was set already - so not fixed yet
thanks
0
 
LVL 16

Accepted Solution

by:
Gyanendra Singh earned 500 total points
ID: 22866059
do one thing try this in gridview rowdatabound event
protected virtual void RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
// here write your code
}
}
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:rwallacej
ID: 22871089
ok I thinkn almost here with this, on page display first time the columns are same as DESIGN view,
however on clicking "Add" to add a new row the column title changes. Not sure why it doesn't get set on first load though even though I use same code!
Protected Sub Production_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles Production.RowDataBound
            If (e.Row.RowType = DataControlRowType.Header) Then
                Me.Production_GasProdGrid.Columns(COLUMN_GasExport).HeaderText = "I hope this sets column!"
            End If
    End Sub

Open in new window

0
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22873324
first time did you bind your datagrid?  bind datagrid on page load ...
0
 

Author Comment

by:rwallacej
ID: 22874096
yes I do bind - the data is shown.

I ended up setting a label on page_load to what I want column headers to be & window.onload javascript to do search/replace. something strange in my case means its not working. I'll accept your answer as this would be way to do it in normal scenario - there must be something wrong with my page
0
 

Author Closing Comment

by:rwallacej
ID: 31512328
thank-you very much for your help
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question