"Alfred Salton" <al***********@hotmail.com> wrote in message
news:2004062811164116807%alfredsalton@hotmailcom.. .
Can anyone show me a simple way to clone an object? In this case, I
have an HTMLTable object which has a hidden header row acting as a
template. I would like to clone the header row and add the new row to
the table. This is trivially simple in javascript using the DOM - does
an equally simple method exist in asp.net code?
Alfred, your question isn't actually a general "clone an object" question,
because the answer to that one is, "if the object implements IClonable, then
just call IClonable.Clone()".
As it is, you'll have to do it manually. For instance, assuming your .aspx
page has:
<table runat="server" id="myTable">
<tr runat="server" id="myHeaderRow">
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
then you'll have to do something like this:
protected System.Web.UI.HtmlControls.HtmlTableRow myHeaderRow;
protected System.Web.UI.HtmlControls.HtmlTable myTable;
private void Page_Load(object sender, System.EventArgs e)
{
HtmlTableRow newHeaderRow = new HtmlTableRow();
newHeaderRow.ID = "newHeaderRow";
newHeaderRow.Height = myHeaderRow.Height; // etc
foreach (HtmlTableCell cell in myHeaderRow.Cells)
{
HtmlTableCell newCell = new HtmlTableCell();
newCell.ID = cell.ID;
newCell.Width = cell.Width; // etc
newHeaderRow.Cells.Add(newCell);
}
myTable.Rows.Insert(1, newHeaderRow);
}
--
John Saunders
johnwsaundersiii at hotmail