Solved

Gridview - Dynamic Header Text

Posted on 2006-10-30
3
3,962 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
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 …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 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