Solved

Gridview HeaderText not changing

Posted on 2008-11-01
7
368 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
Comment Utility
did  AutoGenerateColumns="False" in your gridview .. if not please do that and bind your column and test
0
 

Author Comment

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

Accepted Solution

by:
Gyanendra Singh earned 500 total points
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:rwallacej
Comment Utility
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
Comment Utility
first time did you bind your datagrid?  bind datagrid on page load ...
0
 

Author Comment

by:rwallacej
Comment Utility
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
Comment Utility
thank-you very much for your help
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

763 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

9 Experts available now in Live!

Get 1:1 Help Now