我有两个列表,一个列表计数是16,另一个是4.我需要显示4行和4列 [英] i have two lists one list count is 16 and another one is 4. i need to display 4 rows and 4 cols
本文介绍了我有两个列表,一个列表计数是16,另一个是4.我需要显示4行和4列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个lists.allotment列表计数是16,tailorlist计数是4.我需要显示4行和4列。但它显示4列16行。请告诉我这是什么问题。以下是我的代码
i have two lists.allotment list count is 16 and tailorlist count is 4. i need to display 4 rows and 4 cols. But it displaying 4 columns and 16 rows. Please tell me whats the problem. Below is my code
private void Allocate()
{
int var1 = 0;
Table1.Controls.Clear();
Table1.Rows.Clear();
int count = 0;
IList<allotmentlist> objallotmentlist = new List<allotmentlist>();
objallotmentlist = (IList<allotmentlist>)Session["Allotment"];
IList<tailorlist> objtailorlist = new List<tailorlist>();
objtailorlist = (IList<tailorlist>)Session["TailorDetails"];
TableHeaderRow hrow = new TableHeaderRow();
TableHeaderCell hcell1 = new TableHeaderCell();
hcell1.Text = " ";
hrow.Controls.Add(hcell1);
foreach (TailorList tailor in objtailorlist)
{
TableHeaderCell hcell2 = new TableHeaderCell();
hcell2.Text = tailor.TailorName;
hrow.Controls.Add(hcell2);
count++;
}
Table1.Controls.Add(hrow);
foreach (AllotmentList item in objallotmentlist)
{
TableHeaderRow hrow1 = new TableHeaderRow();
TableHeaderCell hcell3 = new TableHeaderCell();
hcell3.Text = item.ItemName;
hrow1.Controls.Add(hcell3);
foreach (TailorList itm in objtailorlist)
{
TableHeaderCell hcell4 = new TableHeaderCell();
Label lbltime = new Label();
lbltime.ID = "text" + var1;
lbltime.Text = Convert.ToInt32(item.Quantity).ToString();
lbltime.Width = 60;
hcell4.Controls.Add(lbltime);
hrow1.Controls.Add(hcell4);
++var1;
}
Table1.Controls.Add(hrow1);
}
}
推荐答案
TableHeaderRow hrow = new TableHeaderRow();
TableHeaderCell hcell1 = new TableHeaderCell();
hcell1.Text = " ";
hrow.Controls.Add(hcell1);
int objcount = 0;
foreach (AllotmentList item in objallotmentlist)
{
objcount++;
TableHeaderCell hcell2 = new TableHeaderCell();
hcell2.Text = item.ItemName;
hrow.Controls.Add(hcell2);
if (objcount == objtailorlist.Count)
break;
}
Table1.Controls.Add(hrow);
int flag = 0;
for (int i = 0; i < objtailorlist.Count; i++)
{
TableHeaderRow hrow1 = new TableHeaderRow();
TableHeaderCell hcell3 = new TableHeaderCell();
hcell3.Text = objtailorlist[i].TailorName;
hrow1.Controls.Add(hcell3);
flag++;
for (int j = 0; j < objtailorlist.Count; j++)
{
TableHeaderCell hcell4 = new TableHeaderCell();
Label lbltime = new Label();
lbltime.ID = "text" + var1;
lbltime.Text = objallotmentlist[countItem].Quantity.ToString();
lbltime.Width = 60;
hcell4.Controls.Add(lbltime);
hrow1.Controls.Add(hcell4);
countItem++;
++var1;
}
Table1.Controls.Add(hrow1);
if (flag == objtailorlist.Count)
break;
}
}
这篇关于我有两个列表,一个列表计数是16,另一个是4.我需要显示4行和4列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文