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

  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
     
    Alvin Bruney [MVP], Feb 27, 2004
    #2
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.