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