Solved

Gridview - Dynamic Header Text

Posted on 2006-10-30
3
3,945 Views
Last Modified: 2008-01-09
I have an exisiting gridview (named Gridview1) that I dynamically add a column to.

At the moment  the code below works fine but what do I need to add in order for it to return dynamic header text instead of the text "Label1Header"?
(eg. how do I return the dynamic header text  as the defined column data result from an objectdatasource?).

Thanks!



Current Code:-

protected void Page_Load {object sender, EventArgs e}
{
if (!IsPostBack)
BuildColumnsDynamically();
}

private void BuildColumnsDynamically()

{
BoundField nameColumn = new BoundField ();
nameColumn. DataField = "Label1";
NameColumn.HeaderText = "Label1Header"

GridView1.Columns.Add(nameColumn);
}

}







0
Comment
Question by:doolinn
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
bthews earned 500 total points
ID: 17834070
"eg. how do I return the dynamic header text  as the defined column data result from an objectdatasource?"

When you says this, do you mean you want to name the column based on the data you get back from this column?
So you are not always going to know what kind of data is coming back from this column?

As a simple example, lets say that there are the names of states in this column - you don't want to name the column "States", but instead, you want to name it "California" or something like that?

Just trying to determine what you are asking for.

If you are tyring to name the header based on the data, I think you'll have to use the ItemDataBound method (for c#) this event gets fired when data is populated into the grid
0
 

Author Comment

by:doolinn
ID: 17834864

Just to clarify ..to expand on your "States" example ..I intend to show the word "states" in different languages in the header based on a drop down language  box.

ie when English is selected, "States" is shown as the header title, when French is selected the word "États" is in the header etc etc..

I have a translation table in my database that is being queried via an objectdatasource...it returns one record for each language..I'm comforable with that part of the application...I'm just unsure how to link that result back to the gridview header...

hope this clarifies things!

Thanks again for your help
0
 

Author Comment

by:doolinn
ID: 17840804
Its OK..I've worked out that I should be using a headertemplate - works fine now.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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