关于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条.我知道我的循环有问题但不知道应该怎样解决~
我所有的图片已经封装在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条.我知道我的循环有问题但不知道应该怎样解决~
相关文章推荐
- 一个关于多对话框和CListCtrl控件的问题(棘手)。
- 一个关于swfupload控件的问题
- 关于COCOS2DX里面TableView控件使用的问题
- 关于循环的一个问题
- 关于CS模式下,控制一个容器内控件的值问题
- 关于lua table实现的一个问题
- html页面中关于一个table表格中设置上下2个td宽度一致的问题
- 关于《程序员编程宝典》中编写一个函数,作用是把一个char组成的字符串循环右移n位的问题
- 关于FLEX 里控件宽度的一个问题
- solr中一个问题——顺便讨论java中关于中包括main函数以及涉及资源(变量)操作中的类
- 一个关于.Net的SaveFileDialog控件(Winform)的有趣问题
- 关于Repeater控件的一个问题
- 关于.Net 1.1 Windows Forms 控件的一个小问题
- C#写的计数器控件 - 一个关于相对路径使用的问题
- 关于TableView中不止一个section的情况下首个cell的y轴不为0的会造成的问题和解决办法
- 关于tableview 的一个小问题
- 关于遍历向数组中添加值的问题定义一个空数组要写在循环外,否则会被覆盖
- 关于table中一个隐藏的tr,改为显示后与其他tr样式不一样的问题
- 关于多控件调用同一个事件的问题
- 关于一个给二维数组循环赋值问题的本渣研究出的解决办法[C#]