473,324 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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

Sep 28 '05 #1
0 1145

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
2
by: abigblackman | last post by:
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...
0
by: abigblackman | last post by:
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...
0
by: Freddie | last post by:
hi, i need a datagrid w/ 2 headers, the datagrid is bound if( ! IsPostBack), Ken Cox kindly shared some code that addes a new header in the ItemDataBound method, so i moved it to Page_Load, and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.