정말 고맙겠습니다. 이것은 내 문제입니다 :asp.net에서 동적 테이블 채우기?
제품 객체의 ArrayList가 있습니다. 각 제품에는 ID, 이름 및 공급자가 있습니다. arraylist를 반복하고이 값을 셀에 넣기위한 테이블을 만들면 제품에 여러 공급 업체가있을 수 있다는 문제가 발생합니다. 이 경우 ID와 이름은 동일하지만 arraylist의 공급 업체가 다릅니다. 지금까지 코드는 id와 name에 대해 빈 셀을 생성하고 다른 셀을 새 셀에 넣음으로써 이것을 처리합니다.
그러나 모든 공급 업체에 대해 새로운 행을 작성하는 것은 좋지 않습니다. 필자가 원하는 것은 제품에 여러 공급 업체가있는 경우 행의 동일한 셀에있는 모든 공급 업체가 제품 ID를 원한다는 것입니다.
string id = string.Empty;
int count = 0;
public void CreateResultTable(ArrayList result)
{
TableRow row;
TableCell cell;
if (result != null && result.Count > 0)
{
foreach (Item item in result)
{
if (count == 0)
{
row = new TableRow();
id = item.id;
cell = new TableCell();
cell.Text = item.id;
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = item.product;
row.Cells.Add(cell);
cell = new TableCell();
ArrayList levList = item.suppliers;
if (levList != null)
{
string lev = string.Empty;
for (int i = 0; i < levList.Count; i++)
{
lev += levList[i];
}
cell.Text = lev;
row.Cells.Add(cell);
}
else
cell.Text = string.Empty;
row.Cells.Add(cell);
count++;
}
else if (id != item.id)
{
row = new TableRow();
id = item.id;
cell = new TableCell();
cell.Text = item.id;
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = item.product;
row.Cells.Add(cell);
cell = new TableCell();
ArrayList levList = item.suppliers;
if (levList != null)
{
string lev = string.Empty;
for (int i = 0; i < levList.Count; i++)
{
lev += levList[i];
}
cell.Text = lev;
}
else
cell.Text = string.Empty;
row.Cells.Add(cell);
}
else
{
row = new TableRow();
cell = new TableCell();
cell.Text = string.Empty;
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = string.Empty;
row.Cells.Add(cell);
cell = new TableCell();
ArrayList levList = item.suppliers;
if (levList != null)
{
string lev = string.Empty;
for (int i = 0; i < levList.Count; i++)
{
lev += levList[i];
}
cell.Text = lev;
row.Cells.Add(cell);
}
else
cell.Text = string.Empty;
row.Cells.Add(cell);
}
SearchResultLev.Rows.Add(row);
}
SearchResultLev.Visible = true;
SearchResult.Visible = false;
NoSearchResult.Visible = false;
}
else
{
SearchResultLev.Visible = false;
SearchResult.Visible = false;
NoSearchResult.Visible = true;
}
}
나는 u를 sql.Pls에서 그룹화 원인을 사용하여 공급자를 선택할 수 있다고 생각한다. – kbvishnu
Harie - 데이터베이스에 대한 액세스 권한이 없으므로 코드에서 수행 할 수 있다면 정말 좋을 것이다. 불가능하다면 나는 데이터베이스에 접근해야한다. – Andy