473,324 Members | 2,417 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.

Clone an object?

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?

Nov 18 '05 #1
1 2026
"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
Nov 18 '05 #2

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

Similar topics

0
by: Jason Evans | last post by:
Hi All, I am writing my own implementation of queue via a linked list, note not a LinkedList, and was running into trouble with the clone method. I was wondering if anyone could point out some...
4
by: Vincent | last post by:
Hey, I have a problem to understand the underlaying of clone method. Hope someone can help me out. Let's say, clonedObject = originalObject.clone() (syntax may be wrong, but you know what I...
6
by: Amil Hanish | last post by:
I have two classes that I have implemented ICloneable. From my top-level class, how to I clone the base class values: See "how do I clone the base class values" below. Since Clone returns an...
4
by: Steve Teeples | last post by:
I have TreeNodes in a TreeView, each contains unique data in its Tag section. I am trying to 'clone' a TreeNode and then modify the tag data of the cloned TreeNode. What I am seeing is that by...
2
by: Rob R. Ainscough | last post by:
Is there an easy way to clone an object? What I've done in the past is write my own Clone method for each class i create and then just assign property values across objects. I was hoping VS...
8
by: Noozer | last post by:
I'm looking for a way to generate a "clone" of an object. Right now I need to write a Clone function for every class that make and I'd like to have a generic routine. Instead of doing this: For...
1
by: Alex D. | last post by:
hi guys. I need to clone multiple times an object and I am succesfully cloning using the regular serialization process, using a MemoryStream. My problem is that after cloning the object more that...
16
by: Hamed | last post by:
Hello I am developing a utility to be reused in other programs. It I have an object of type Control (a TextBox, ComboBox, etc.) that other programmers use it in applications. they may set some...
14
by: Hamed | last post by:
Hello It seems that I should implement ICloneable to implement my own clone object. the critical point for me is to make a control object based on another control object that all of its event...
7
by: =?Utf-8?B?Sm9lbCBNZXJr?= | last post by:
I have created a custom class with both value type members and reference type members. I then have another custom class which inherits from a generic list of my first class. This custom listneeds...
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...
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...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.