Datagrid dynamically generated template columns dissapearing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • abigblackman@gmail.com

    Datagrid dynamically generated template columns dissapearing

    Hi,

    I have a datagrid that is programatically generated with template
    columns.
    There seems to be something happening where only the last record is
    rendered with any data.

    I start by creating the template columns like this:
    <code>
    TemplateColumn tc.HeaderText = "Name";

    ColumnTemplate ct = new ColumnTemplate ();
    Label lbl = new Label ();
    lbl.ID = "lblName";

    ct.SetControl ( lbl );
    tc.ItemTemplate = ct;

    dgResults.Colum ns.Add ( tc );
    </code>
    Where ColumnTemplate looks like:
    <code>
    class ColumnTemplate : ITemplate {

    Control con;

    public void InstantiateIn ( Control container ) {
    container.Contr ols.Add ( con );
    }

    public void SetControl ( Control con ) {
    this.con = con;
    }
    }

    </code>

    Finally when each item is bound to the column I do something like:
    <code>
    // name
    lbl = (Label)e.Item.F indControl ( "lblName" );
    lbl.Text = person.LastName + ", " + person.FirstNam e;
    </code>

    When stepping through the debugger I can see the correct value being
    assigned to the label.

    However when I view the output the only data is contained in the last
    row. All the previous rows are empty eg:
    <code>
    <table cellspacing="0" rules="all" border="1"
    style="border-collapse:collap se;">
    <tr>
    <td>Name</td><td>Company</td>
    </tr><tr>
    <td></td><td></td>
    </tr><tr>
    <td></td><td></td>
    </tr><tr>
    <td><span id="ctl00_pageC ontent_ctl00_ct l04_lblName">My
    Name</span></td><td><span
    id="ctl00_pageC ontent_ctl00_ct l04_lblCompany" >My Company</span></td>
    </tr>
    </table>
    </code>

    Any ideas what might be going on here?

    Cheers,

    Marshall

Working...