首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

与“System.Web.UI.WebControls.TableRowCollection.Add(System.Web.UI.WebControls.Tab

2012-01-09 
与“System.Web.UI.WebControls.TableRowCollection.Add(System.Web.UI.WebControls.TableRow)”最匹配的重

与“System.Web.UI.WebControls.TableRowCollection.Add(System.Web.UI.WebControls.TableRow)”最匹配的重载方法具有一些无效参数
编译错误    
说明:   在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。    

编译器错误信息:   CS1502:   与“System.Web.UI.WebControls.TableRowCollection.Add(System.Web.UI.WebControls.TableRow)”最匹配的重载方法具有一些无效参数  

源错误:  

   

行   33:                                   r.Cells.Add(c);  
行   34:                           }  
行   35:                           Table1.Rows.Add(r);  
行   36:                   }  
行   37:           }  
   

源文件:   e:\ASP.NET\Samples\HtmlTable.aspx.cs         行:   35    

这个错误怎么解决?  
这是一个动态创建表格的程序,各位帮我看看哈,页面上有一个Table1

        protected   void   Page_Load(object   sender,   EventArgs   e)
        {
                int   row   =   0;
                int   numrows   =   Int32.Parse(Select1.Value);
                int   numcells   =   Int32.Parse(Select2.Value);

                for   (int   j   =   0;   j   <   numrows;   j++)
                {
                        HtmlTableRow   r   =   new   HtmlTableRow();
                        //设定背景颜色
                        if   (row   %   2   ==   1)
                        {
                                r.BgColor   =   "Gainsboro ";
                        }
                        row++;
                        for   (int   i   =   0;   i   <   numcells;   i++)
                        {
                                HtmlTableCell   c   =   new   HtmlTableCell();
                                c.Controls.Add(new   LiteralControl( "行 "   +   j.ToString()   +   ",列 "   +   i.ToString()));
                                r.Cells.Add(c);
                        }
                        Table1.Rows.Add(r);


                }
        }


[解决办法]
System.Web.UI.WebControls.TableRow
HtmlTableRow r = new HtmlTableRow();
Table1.Rows.Add(r);
--
楼主,HtmlTableRow是TableRow的子类么?如不是,你用错了。

[解决办法]
Table1.Rows.Add()参数是TableRow类型
你用的是HtmlTableRow类型
HtmlTableRow是 System.Web.UI.HtmlControls里的
TableRow是 System.Web.UI.WebControls里的
不是一回事
用TableRow吧

个人见解,共同学习

热点排行