可以在表等号复制到另一台?如果没有,那么怎么样? [英] Can a table be copied to another table by an equal sign? If not, then how?

查看:170
本文介绍了可以在表等号复制到另一台?如果没有,那么怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何能表控制被复制?

 表2 = table1的?

ASP.NET C#Visual Studio 2008的表控制。

的原因是,它适用于字符串。假设下面的字符串是表。

 串饱满;
串userinput;
全=满+ userinput;


解决方案

编辑:自2010年6月在回答这个问题前,我已经使用jQuery做这种事情花了很多时间在客户端上。如果有兴趣在这种方法中,考虑了jQuery的clone()和append(),()后,前()和相关方法。
结束修改

没有,你不能。表,像任何其他的控制,是引用类型。这意味着,复制它只是拷贝到真实对象实例的引用。因为它没有实施 System.ICloneable 你必须创建一个新的,然后逐一手动拷贝一个属性。

我会好奇地想知道为什么你正在尝试做的这一点,因为它似乎并没有遵循任何的那个我熟悉的最佳实践。你能描述你正在尝试做的?

有一件事情你可以做的是复制表的内容,虽然这不会照搬其他属性,如样式和细胞填充等:

 保护无效CopyTable()
    {
        VAR clontable =新HTMLTABLE();
        VAR MYTBL = form1.FindControl(MYTABLE)作为HTMLTABLE;
        如果(MYTBL!= NULL)
        {
            HtmlTableRow myrow;
            HtmlTableCell了myCell;            的for(int i = 0; I< mytbl.Rows.Count - 1;我++)
            {
                myrow =新HtmlTableRow();
                对于(INT J = 0; J< mytbl.Rows [I] .Cells.Count - 1; J ++)
                {
                    了myCell =新HtmlTableCell();
                    mycell.InnerHtml = mytbl.Rows [I] .Cells [J] .InnerHtml;
                    myrow.Cells.Add(了myCell);
                }
                clontable.Rows.Add(myrow);
            }
            form1.Controls.Add(clontable);
        }
    }

How can table controls be copied?

table2=table1?

ASP.NET C# Visual Studio 2008 table control.

The reason is that it works for strings. Assume the below strings to be tables.

string full; 
string userinput;
full = full + userinput;

解决方案

Edit: Since answering this question back in June 2010, I have spent a lot of time using jQuery to do this kind of thing on the client. If interested in this approach, look into the jQuery clone() and append(), after(), before() and related methods. End Edit

No, you can't. Table, like any other control, is a reference type. It means that copying it just copies a reference to the real object instance. Because it doesn't implement System.ICloneable you have to create a new one and then copy properties manually one by one.

I would be curious to know why you are trying to do this, because it doesn't seem to follow any of the best practices that I am familiar with. Could you describe what you are trying to do?

One thing you could do is copy the contents of a table, although this won't copy the other properties such as styles and cell-padding etc:

    protected void CopyTable()
    {
        var clontable= new HtmlTable();
        var mytbl = form1.FindControl("mytable") as HtmlTable;
        if (mytbl != null)
        {
            HtmlTableRow myrow;
            HtmlTableCell mycell;

            for (int i = 0; i < mytbl.Rows.Count - 1; i++)
            {
                myrow = new HtmlTableRow();
                for (int j = 0; j < mytbl.Rows[i].Cells.Count - 1; j++)
                {
                    mycell = new HtmlTableCell();
                    mycell.InnerHtml = mytbl.Rows[i].Cells[j].InnerHtml;
                    myrow.Cells.Add(mycell);
                }
                clontable.Rows.Add(myrow);
            }
            form1.Controls.Add(clontable);
        }
    }

这篇关于可以在表等号复制到另一台?如果没有,那么怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆