Datagrid Headers

C

Chris Newald

Hello,

I have a simple gridview with one column on a web page. I need to be able to
set the column titles ("Header Title" below) programatically. How would I
do this easily in C#? I tried inserting an ASP Label but I cannot get the
FindControl to work for the Header Template.

<asp:DataGrid ID="alertGrid" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<b>Header Title</b>
</HeaderTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

Thanks in advance,
Chris
 
E

Eliyahu Goldin

<HeaderTemplate>
<asp:Label runat="server" id="lblHeader" Text="Header Title" />
</HeaderTemplate>
 
K

keithrull

Hello,

I have a simple gridview with one column on a web page. I need to be able to
set the column titles ("Header Title" below) programatically. How would I
do this easily in C#? I tried inserting an ASP Label but I cannot get the
FindControl to work for the Header Template.

<asp:DataGrid ID="alertGrid" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<b>Header Title</b>
</HeaderTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

Thanks in advance,
Chris

Add a label control in the header template then change it's value
inside the ItemDataBound event. I think it would be easier if you just
not put a header tempate and just use the column value of your
datasource instead.

Keith Rull
http://www.keithrull.com/
http://www.devpinoy.org/
 
Joined
Oct 25, 2007
Messages
2
Reaction score
0
I think this should work for you,

alertGrid.Columns[0].HeaderText="Header Title";

where 0 is the index of column
 

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

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top