Solved

Gridview - Dynamic Header Text

Posted on 2006-10-30
3
3,980 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
[X]
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
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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 …
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

726 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