且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

错误为“具有相同ID的多个控件"当我动态创建行时

更新时间:2023-11-17 13:53:58

我的猜测是您正在将调用此代码的代码的count设置为0.第一次起作用吗?

为什么只在计数为0时才添加新行?这对我来说毫无意义.

每次调用此代码段时,您还将创建一个全新的表,并且该表中的元素始终具有相同的名称,因此,如果两次调用它,则会得到两个ID冲突的表.那与您的文字描述不符,因此我怀疑您不想每次都创建一个新表,而是想将一个表传递给此方法.然后,您可以使用table.Controls.Count或类似方法获取可用于id的行计数,而不是依赖于count变量.
My guess is that you''re setting count to 0 in the code that calls this. Does it work the first time?

Why do you only add a new row if the count is 0? That makes no sense to me.

You are also creating a whole new table each time this snippet is called, and the elements within that table always have the same name, so if you call it twice you get two tables with ***ing IDs. That doesn''t match what your text description is, so I suspect you don''t want to make a new table each time, but instead you want to pass a table into this method. You can then use table.Controls.Count or similar to get a row count that you can use for an id, instead of relying on the count variable.


您必须更改计数值在For循环退出后.
You have to change the count value after the For loop exits.


在count内放入for循环...........
put count++ inside for loop..........