Datagrid Headers

Discussion in 'ASP .Net' started by Chris Newald, Nov 15, 2007.

  1. Chris Newald

    Chris Newald Guest

    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
     
    Chris Newald, Nov 15, 2007
    #1
    1. Advertising

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


    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin


    "Chris Newald" <> wrote in message
    news:...
    > 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
    >
    >
     
    Eliyahu Goldin, Nov 15, 2007
    #2
    1. Advertising

  3. Chris Newald

    keithrull Guest

    On Nov 15, 11:50 am, "Chris Newald" <> wrote:
    > 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/
     
    keithrull, Nov 15, 2007
    #3
  4. Chris Newald

    Saad

    Joined:
    Oct 25, 2007
    Messages:
    2
    Location:
    Karachi
    I think this should work for you,

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

    where 0 is the index of column
     
    Saad, Nov 16, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Douglas Gage

    Datagrid Headers???

    Douglas Gage, Jan 15, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    500
    Douglas Gage
    Jan 15, 2004
  2. Nimbus Dorkus

    locking headers in the Datagrid

    Nimbus Dorkus, Jul 9, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    414
    Nimbus Dorkus
    Jul 9, 2003
  3. dont bother
    Replies:
    0
    Views:
    849
    dont bother
    Mar 3, 2004
  4. Phil
    Replies:
    4
    Views:
    717
    Gabriel Genellina
    Jan 17, 2010
  5. Ian
    Replies:
    2
    Views:
    2,075
Loading...

Share This Page