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

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

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:
    591
    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,475
    Alvin Bruney [MVP]
    May 27, 2004
  3. Patrick Olurotimi Ige
    Replies:
    1
    Views:
    715
    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:
    4,216
    Eliyahu Goldin
    Nov 6, 2005
  5. Replies:
    3
    Views:
    2,689
  6. Andy Wang

    change HeaderText of DataGrid in PreRender().

    Andy Wang, May 12, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    6
    Views:
    714
    Eliyahu Goldin
    May 16, 2004
  7. Ravi Gudlavalleti

    How do I change the headertext of a datagrid column programmatically

    Ravi Gudlavalleti, Jun 17, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    335
    Ken Cox [Microsoft MVP]
    Jun 18, 2004
  8. Sangra M via .NET 247

    Change HeaderText of datagrid after binding

    Sangra M via .NET 247, Mar 14, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    403
    Sylvain Lafontaine
    Mar 14, 2005
Loading...