473,385 Members | 1,357 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,385 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 1148

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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.