Solved

Gridview HeaderText not changing

Posted on 2008-11-01
7
373 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

713 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