DataGrid Dynamic HeaderText

Discussion in 'ASP .Net Datagrid Control' started by Seli, Mar 3, 2004.

  1. Seli

    Seli Guest

    Hell

    How can I change the headerText of an AutoGenerateColumns DataGrid

    myDataGrid.DataSource=ds.Tables["Products"].DefaultView
    myDataGrid.DataBind()
    myDataGrid.Columns[0].HeaderText="MARCEL";

    in the third line I get always an exception. myDataGrid.Colums.count Returns 0!

    Thank
    Seli
     
    Seli, Mar 3, 2004
    #1
    1. Advertising

  2. Seli

    SB Guest

    Seli,
    You can do that in the ItemCreated event.of the DataGrid.
    Make sure that you only apply the value when the IteMType is of type header
    =>

    //I write from scratch, not Iin VS so there might be typo mistakes
    if (e.Item.ItemType==ListItemType.HeaderItem){
    e.Item[0].HeaderText="MARCEL";
    }
    Selim

    "Seli" <> wrote in message
    news:...
    > Hello
    >
    > How can I change the headerText of an AutoGenerateColumns DataGrid?
    >
    > myDataGrid.DataSource=ds.Tables["Products"].DefaultView;
    > myDataGrid.DataBind();
    > myDataGrid.Columns[0].HeaderText="MARCEL";
    >
    > in the third line I get always an exception. myDataGrid.Colums.count

    Returns 0!!
    >
    > Thanks
    > Seli
     
    SB, Mar 3, 2004
    #2
    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. Andy Wang
    Replies:
    0
    Views:
    504
    Andy Wang
    May 12, 2004
  2. =?Utf-8?B?bWc=?=

    Set headertext in datagrid programatically

    =?Utf-8?B?bWc=?=, May 26, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,353
    Alvin Bruney [MVP]
    May 27, 2004
  3. Patrick Olurotimi Ige
    Replies:
    1
    Views:
    616
    Patrick Olurotimi Ige
    Mar 11, 2005
  4. Øyvind Isaksen

    Change HeaderText in datagrid

    Øyvind Isaksen, Nov 6, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    3,995
    Eliyahu Goldin
    Nov 6, 2005
  5. Replies:
    3
    Views:
    2,480
Loading...

Share This Page