关于table控件的一个疑难问题(涉及循环)

我用的是Table控件,我有个需求Table每行显示10张图片,
我所有的图片已经封装在IList<string>imglist=new list<>();
首先我获取了有多少张图片并算出会有多少行
 //图片的数量
int count = imglist.Count;
//计算会有多少行
int rowCount = count % 10 > 0 ? count / 10 + 1 : count / 10;
接着代码如下
           //首先动态加载行
            for (int j = 0; j < rowCount;j++)
            {
                TableRow tr = new TableRow();
                Table1.Rows.Add(tr);
              
                for (int i = 0; i < count; i++)
                {
                    TableCell tc = new TableCell();
                    Image img = new Image();
                    img.ID = "img" + i.ToString();
                    img.Width = Convert.ToUInt16(100);
                    img.Height = Convert.ToUInt16(100);
                    img.Attributes.Add("onclick", "showimage(this)");
                    img.ImageUrl = path + "\\" + imglist[i].ToString();
                    tc.Controls.Add(img);
                    tr.Cells.Add(tc);
                }
            }
我图片总共有12张,我希望达到的效果是第一行显示10条,第二行显示2条。结果两行都显示的是前10条.我知道我的循环有问题但不知道应该怎样解决~

posted @ 2007-07-16 15:34  思然  阅读(245)  评论(0编辑  收藏  举报