Datagrid dynamically generated template columns dissapearing

  • Thread starter Thread starter abigblackman
  • Start date Start date
A

abigblackman

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.Columns.Add ( tc );
</code>
Where ColumnTemplate looks like:
<code>
class ColumnTemplate : ITemplate {

Control con;

public void InstantiateIn ( Control container ) {
container.Controls.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.FindControl ( "lblName" );
lbl.Text = person.LastName + ", " + person.FirstName;
</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:collapse;">
<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_pageContent_ctl00_ctl04_lblName">My
Name</span></td><td><span
id="ctl00_pageContent_ctl00_ctl04_lblCompany">My Company</span></td>
</tr>
</table>
</code>

Any ideas what might be going on here?

Cheers,

Marshall
 
Hi Brock,

It's definatly recreated. All the rows are showing but they are all
empty except for the very last row which contains the correct data.
 
Back
Top