Changing Header Text of Datagrid Programatically

I have a datagrid. It is bound to an object data source.  I want to change the header text in one of the columns each time the data changes – which is basically at every postback.   By way of background, I created template fields using the Fields dialog box.  I have listed a portion of the code from the datagrid I am working on below.  I want to programmatically change  the headertext “services”.  I have tried using  findcontrol but I keep getting a null exception.  Any ideas would be appreciated. Thanks

 

<asp:TemplateField HeaderText="Services" SortExpression="Services">

<EditItemTemplate>

<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Services") %>'></asp:TextBox>

</EditItemTemplate>

<ItemTemplate>

<asp:Label ID="Label3" runat="server" Width="450px" Text='<%# Bind("Services") %>'></asp:Label>

</ItemTemplate>

<ItemStyle HorizontalAlign="Left" />

</asp:TemplateField>

0
KevinGW
3/4/2009 2:43:03 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

2 Replies
503 Views

Similar Articles

[PageSpeed] 26

user this

GridView1.HeaderRow.Cells(Index).Text = "your Text Here"
 

Regards...
Nassar, Rami
My Blog || E-Mail

Don't forget to click "Mark as Answer" on the post that helped you.

This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
0
rami_nassar
3/4/2009 3:49:43 AM

Hello,

U can use following

 

protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    
            if (e.Row.RowType == DataControlRowType.Header)
            {             
                    e.Row.Cells[0].Text = "Your Text";
              
            }
       }


Thanks,
Kalpana Patel

Remember to click “Mark as Answer” on the post, if it helps you.
0
kyuti
3/4/2009 4:00:06 AM
Reply: