您的位置:首页 > 其它

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

2007-07-16 15:34 344 查看
我用的是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条.我知道我的循环有问题但不知道应该怎样解决~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: