Saturday, March 24, 2012

Setting text in HeaderTemplate, how?

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"Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
news:eSBPQ7JZHHA.4772@.TK2MSFTNGP05.phx.gbl...

> 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...?
"Mark Rae" <mark@.markNOSPAMrae.com> wrote in message
news:eXywCWKZHHA.1240@.TK2MSFTNGP04.phx.gbl...
> "Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
> news:eSBPQ7JZHHA.4772@.TK2MSFTNGP05.phx.gbl...
>
> 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
"Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
news:evuwvsKZHHA.4264@.TK2MSFTNGP05.phx.gbl...

> Yes, I want to overwrite the text in the HeaderTemplate
<MyGridView>.Columns[0].HeaderText = "Inbox";
"Mark Rae" <mark@.markNOSPAMrae.com> wrote in message
news:OESfc9KZHHA.4220@.TK2MSFTNGP03.phx.gbl...
> "Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
> news:evuwvsKZHHA.4264@.TK2MSFTNGP05.phx.gbl...
>
> <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?
"Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
news:OMjGRPLZHHA.1008@.TK2MSFTNGP03.phx.gbl...

> 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";
"Mark Rae" <mark@.markNOSPAMrae.com> wrote in message
news:egvLmTLZHHA.4552@.TK2MSFTNGP05.phx.gbl...
> "Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
> news:OMjGRPLZHHA.1008@.TK2MSFTNGP03.phx.gbl...
>
> 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
"Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
news:O2nl$JNZHHA.4940@.TK2MSFTNGP05.phx.gbl...

> 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...

0 comments:

Post a Comment