boundcolumn headertext set to a code-behind variable?

J

John E.

I have an ASP.NET datagrid with several bound columns. I need to make the
header of some of these columns display a string that is generated from the
code behind (i.e. a dynamic header). How is this done?

I have tried with both a templatecolumn and boundcolumn. I thought it might
be something like: HeaderText='<%# DataBinder.Eval(Container,
"DataItem.myVariable") %>' or HeaderText='<% Response.Write(myVariable); %>
But, neither worked, nor did several variations. I just want the headertext
to display myVariable which is declared as a string. Can anyone please
assist?

TIA,
John
 
E

Eliyahu Goldin

John,

In code-behind (not in .aspx file) you can set HeaderText property via
Columns property of the datagrid.

Eliyahu
 
J

John E.

I tried that originally, and it sets the headertext during page load, but
after it is loaded the headertext keeps getting reset to the .aspx value.
Even if I remove the HeaderText item from the .aspx portion.

So, if it is done in the code-behind, how do you make sure it is the final
setting that the headertext is set to?

Sorry about my ignorance, but I am used to doing applications, not asp.
 
E

Eliyahu Goldin

Try doing this in PreRender event.

Eliyahu

John E. said:
I tried that originally, and it sets the headertext during page load, but
after it is loaded the headertext keeps getting reset to the .aspx value.
Even if I remove the HeaderText item from the .aspx portion.

So, if it is done in the code-behind, how do you make sure it is the final
setting that the headertext is set to?

Sorry about my ignorance, but I am used to doing applications, not asp.
 
J

John E.

Got it. Thanks! Setting the sessions to their local/member variables
within the init, also helped to keep me from loosing those assignments and
now everything renders properly :D

Thanks again,
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top