Solved

Gridview - Dynamic Header Text

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

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

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
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…

895 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

17 Experts available now in Live!

Get 1:1 Help Now