Solved

Gridview HeaderText not changing

Posted on 2008-11-01
7
369 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Log4Net custom Appender not being fired. 5 76
Calling stored proc in EDMX 11 24
Angular JS Route 3 54
C# MVC and a global static factory that never dies 4 49
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now