Changing datagrids Headertexts /events in an dynamically created datagrid

Discussion in 'ASP .Net Web Controls' started by Anna Schmidt, Feb 27, 2004.

  1. Anna Schmidt

    Anna Schmidt Guest

    Hello,

    I'm currently working on a dynamic generation of a Datagrid (without aspx )
    files.

    the basic Idea is sending a DataTable to my viewDatagrid class, so the
    columns are determined and dates/numbers are formatted, styles are set etc.,
    that works fine. so need to define fields in the aspx.files

    Everything works fine, except I can't change HeaderTexts of
    Datagrid.Columns. Besides, I can't bound events to this dynamic dg2.

    viewDataGrid vd = new viewDataGrid(myDatatable);

    DataGrid dg2 = new DataGrid();

    dg2 = vd .GetDataGrid(); // after formatting a new Datagrid is returend
    //databind is already happened.


    dg2.Columns[1].HeaderText ="Name"; // doesn't work at all, instead
    fieldnames from datatable used instead

    dg2.ShowHeader = true; ///-->works fine

    dg2.ShowFooter = false; ///-->works fine


    this.Controls.Add(dg2); // adding in the pageload methods

    I think It's because databinding already happened in the GetDataGrid()
    method. but how to change headertexts afterwords? i want to set my
    headertexts in the aspx.cs file, not in my Helper-Class ???

    Has anyone got an idea, why this doesn't work? and why can i change the
    general preferences, but not the data?

    Or is there a better solution for dynamically creating a datagrid from a
    datatable?

    any help is appreciated.

    Thankyou as.
     
    Anna Schmidt, Feb 27, 2004
    #1
    1. Advertising

  2. when you bind to the datagrid you will need to place code inside the
    itemdatabound event handler to adjust the title of the columns.
    if(e.item.itemtype == listitem.header)
    e.item.cells[0].text = "new header";

    roughly

    --
    Regards,
    Alvin Bruney [ASP.NET MVP]
    Got tidbits? Get it here...
    http://tinyurl.com/3he3b
    "Anna Schmidt" <> wrote in message
    news:c1o2ir$1knlbp$-berlin.de...
    > Hello,
    >
    > I'm currently working on a dynamic generation of a Datagrid (without

    aspx )
    > files.
    >
    > the basic Idea is sending a DataTable to my viewDatagrid class, so the
    > columns are determined and dates/numbers are formatted, styles are set

    etc.,
    > that works fine. so need to define fields in the aspx.files
    >
    > Everything works fine, except I can't change HeaderTexts of
    > Datagrid.Columns. Besides, I can't bound events to this dynamic dg2.
    >
    > viewDataGrid vd = new viewDataGrid(myDatatable);
    >
    > DataGrid dg2 = new DataGrid();
    >
    > dg2 = vd .GetDataGrid(); // after formatting a new Datagrid is returend
    > //databind is already happened.
    >
    >
    > dg2.Columns[1].HeaderText ="Name"; // doesn't work at all, instead
    > fieldnames from datatable used instead
    >
    > dg2.ShowHeader = true; ///-->works fine
    >
    > dg2.ShowFooter = false; ///-->works fine
    >
    >
    > this.Controls.Add(dg2); // adding in the pageload methods
    >
    > I think It's because databinding already happened in the GetDataGrid()
    > method. but how to change headertexts afterwords? i want to set my
    > headertexts in the aspx.cs file, not in my Helper-Class ???
    >
    > Has anyone got an idea, why this doesn't work? and why can i change the
    > general preferences, but not the data?
    >
    > Or is there a better solution for dynamically creating a datagrid from a
    > datatable?
    >
    > any help is appreciated.
    >
    > Thankyou as.
    >
    >
     
    Alvin Bruney [MVP], Feb 27, 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. ree32
    Replies:
    4
    Views:
    827
    ree32
    Feb 21, 2005
  2. ree32
    Replies:
    1
    Views:
    381
    =?Utf-8?B?SmltIEhlYXZleQ==?=
    Feb 18, 2005
  3. Anna
    Replies:
    1
    Views:
    383
  4. msimmons
    Replies:
    0
    Views:
    544
    msimmons
    Jul 16, 2009
  5. Faredoon Irani via .NET 247

    registering events for dynamically declared DataGrids

    Faredoon Irani via .NET 247, Aug 5, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    177
    Faredoon Irani via .NET 247
    Aug 5, 2004
Loading...

Share This Page