进一步..c#循环添加 HtmlTableCell[][] td 的问题
现在是4*4的td 求个循环把我的 HtmlTableCell[,] td弄成4*n的,就像{ tdn1, tdn2, tdn3, tdn4 }
// table的单元格
HtmlTableCell td11 = new HtmlTableCell();
HtmlTableCell td12 = new HtmlTableCell();
HtmlTableCell td13 = new HtmlTableCell();
HtmlTableCell td14 = new HtmlTableCell();
HtmlTableCell td21 = new HtmlTableCell();
HtmlTableCell td22 = new HtmlTableCell();
HtmlTableCell td23 = new HtmlTableCell();
HtmlTableCell td24 = new HtmlTableCell();
HtmlTableCell td31 = new HtmlTableCell();
HtmlTableCell td32 = new HtmlTableCell();
HtmlTableCell td33 = new HtmlTableCell();
HtmlTableCell td34 = new HtmlTableCell();
HtmlTableCell td41 = new HtmlTableCell();
HtmlTableCell td42 = new HtmlTableCell();
HtmlTableCell td43 = new HtmlTableCell();
HtmlTableCell td44 = new HtmlTableCell();
HtmlTableCell[,] td = { { td11, td12, td13, td14 }, { td21, td22, td23, td24 }, { td31, td32, td33, td34 }, { td41, td42, td43, td44 }};
例如可以添加--------------------编程问答-------------------- 问题好像太模糊了,
HtmlTableCell td51 = new HtmlTableCell();
HtmlTableCell td52 = new HtmlTableCell();
HtmlTableCell td53 = new HtmlTableCell();
HtmlTableCell td54 = new HtmlTableCell();
变成
HtmlTableCell[,] td = { { td11, td12, td13, td14 }, { td21, td22, td23, td24 }, { td31, td32, td33, td34 }, { td41, td42, td43, td44 },{ td51, td52, td53, td54 }};
是这样的。类似用个循环命名--------------------编程问答-------------------- 二维数组?
HtmlTableCell td11 = new HtmlTableCell();
HtmlTableCell td12 = new HtmlTableCell();
HtmlTableCell td13 = new HtmlTableCell();
HtmlTableCell td14 = new HtmlTableCell();
把上面的变成:
for(int n=1;n<10;n++)
{
HtmlTableCell tdn1 = new HtmlTableCell();
HtmlTableCell tdn2 = new HtmlTableCell();
HtmlTableCell tdn3 = new HtmlTableCell();
HtmlTableCell tdn4 = new HtmlTableCell();
}//显然我这样命名是不对的 求正解!
还有就是定义二维数组的问题了
HtmlTableCell[,] td = { { td11, td12, td13, td14 }, { td21, td22, td23, td24 }, { td31, td32, td33, td34 }, { td41, td42, td43, td44 }}; //把他也变成循环...
循环赋值?
类似 td[i,j]=... --------------------编程问答--------------------
是啊,虽然我实现了td[i,j]可是不满足啊,我写的是固定的4*4,想用循环变成活动的...(嘿嘿,td[i,j]也是下午发帖子问出来的,我是新手大家见谅) --------------------编程问答-------------------- 莫非下午大家都在工作?? --------------------编程问答-------------------- 不是很明白
--------------------编程问答--------------------
protected void Page_Load(object sender, EventArgs e)
{
HtmlTableCell[,] cellCollection = SetCellCollection(4, 5);
}
public HtmlTableCell[,] SetCellCollection(int m, int n)
{
HtmlTableCell[,] cellCollection = new HtmlTableCell[m, n];
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
HtmlTableCell cell = new HtmlTableCell();
cell.InnerHtml = (i * n + j).ToString();
cellCollection[i, j] = cell;
}
}
return cellCollection;
}
--------------------编程问答-------------------- 哎...我总是说不请问题.... --------------------编程问答-------------------- 在顶一次 好心的人们快来帮帮忙~~~
int s = 0;
while (slie != null)
{
//分割行内容
char[] separator = { ','};
String[] splitString=new String[100];
splitString = slie.Split(separator);
for (int i = 0; i < splitString.Length;i++ )
{
ll[i] = new Label();
ll[i].Text=splitString[i];
td[s,i].Controls.Add(ll[i]);
//就是这里的问题了,我固定限制td[s,i]容易造成数组越界!
tr[s].Controls.Add(td[s,i]);
}
tabInfo.Controls.Add(tr[s]);
this.Label2.Text = "ここでファイルの内容";
slie = sr.ReadLine();//sline就是每行的数据
s++;
}
附上一张图片 --------------------编程问答-------------------- 只能回复3次 ...换了个马甲
研究了一上午你的代码,呵呵,果然弄出来了 谢谢了!!!
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
HtmlTableCell cell = new HtmlTableCell();
cellCollection[i, j] = cell;
//主要就是这里,以前没想到,呵呵,比起编程思路果然最重要啊!
}
}
补充:.NET技术 , C#