Setting text in HeaderTemplate, how??

J

Jeff

ASP.NET 2.0

I have a webpage which contains a GridView. I want this GridView's
HeaderTemplate to display the text "Inbox" or "Outbox"... So I think I need
to set the value in the code behind file... Anyone got any tips about how to
do this?

Jeff
 
M

Mark Rae

I have a webpage which contains a GridView. I want this GridView's
HeaderTemplate to display the text "Inbox" or "Outbox"... So I think I
need to set the value in the code behind file... Anyone got any tips about
how to do this?

When you say HeaderTemplate, do you mean you want to overwrite the text in
the first column's header...?

Or are you actually thinking of the GridView's Caption property...?
 
J

Jeff

Mark Rae said:
When you say HeaderTemplate, do you mean you want to overwrite the text in
the first column's header...?

Or are you actually thinking of the GridView's Caption property...?

Yes, I want to overwrite the text in the HeaderTemplate
 
J

Jeff

Mark Rae said:
Yes, I want to overwrite the text in the HeaderTemplate

<MyGridView>.Columns[0].HeaderText = "Inbox";

thanks, but somehow the text isn't displayed. I here post the markup of my
gridview so you can see if there are something wrong with the markup:
<asp:GridView ID="gridMessage"
Width="100%"
AutoGenerateColumns="false"
OnRowDataBound="gridMessage_RowDataBound"
runat="server"
BorderWidth="0"
BorderStyle="None"
RowStyle-BackColor="#EBEBEB"
AlternatingRowStyle-BackColor="#D9D9D9"
DataSourceID="odsMessage">
<Columns>
<asp:TemplateField ControlStyle-Width="100%"
HeaderStyle-Width="100%">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<some text here>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

In the open event I set the text:
gridMessage.Columns[0].HeaderText = "Inbox";

In order to keep the markup I posted here tidy I removed the contents inside
the column and replaced it with this text <some text here>....

Any suggestions?
 
M

Mark Rae

In the open event I set the text:
gridMessage.Columns[0].HeaderText = "Inbox";

The "open" event...? Do you mean Page_Load?

If so, that's too early - you need to set this *after* the data has been
bound to the GridView, otherwise it will be overwritten...

gridMessage.DataSource = "<......>";
gridMessage.DataBind();
gridMessage.Columns[0].HeaderText = "Inbox";
 
J

Jeff

Mark Rae said:
In the open event I set the text:
gridMessage.Columns[0].HeaderText = "Inbox";

The "open" event...? Do you mean Page_Load?

If so, that's too early - you need to set this *after* the data has been
bound to the GridView, otherwise it will be overwritten...

gridMessage.DataSource = "<......>";
gridMessage.DataBind();
gridMessage.Columns[0].HeaderText = "Inbox";

Yes, I mean Page_Load

I've tryed to set it in the gridMessage_RowDataBound (RowDataBound) which
didn't help - no HeaderText displayed.

Thanks for this example:
gridMessage.DataSource = "<......>";
gridMessage.DataBind();
gridMessage.Columns[0].HeaderText = "Inbox";
But I doesn't make any call to DataBind() in the code-behind file. All is
done in the markup... So I'm a bit lost about where to place this
gridMessage.Columns[0].HeaderText = "Inbox";

Any suggestion
 
M

Mark Rae

Thanks for this example:
gridMessage.DataSource = "<......>";
gridMessage.DataBind();
gridMessage.Columns[0].HeaderText = "Inbox";
But I doesn't make any call to DataBind() in the code-behind file. All is
done in the markup... So I'm a bit lost about where to place this
gridMessage.Columns[0].HeaderText = "Inbox";

Ah right...

In which case, you could try Page_PreRender...
 
J

Jeff

Mark Rae said:
Thanks for this example:
gridMessage.DataSource = "<......>";
gridMessage.DataBind();
gridMessage.Columns[0].HeaderText = "Inbox";
But I doesn't make any call to DataBind() in the code-behind file. All is
done in the markup... So I'm a bit lost about where to place this
gridMessage.Columns[0].HeaderText = "Inbox";

Ah right...

In which case, you could try Page_PreRender...

Thanks... At first Page_PreRender didn't help, so I was tweaking around my
code and also tryed the PreRender event of my GridView... it didn't help
here either... But hey I've found why it didn't work... the markup of my
GridView contains <HeaderTemplate></HeaderTemplate>... After I removed these
tags the gridMessage.Columns[0].HeaderText = "Inbox"; works as a dream...

I post how I've solved it just in case somebody else would came across the
same problem and are looking for a solution

Jeff
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top