110,590
社区成员
发帖
与我相关
我的任务
分享
string aa="blue,red,blue,red,red,yellow" ;
string bb="12,12,13,13,14,14" ;
string cc = "1,1,1,1,1,2";
string[] color = aa.Split(",".ToCharArray());
string[] size = bb.Split(",".ToCharArray());
string[] count = cc.Split(",".ToCharArray());
DataTable dt = new DataTable();
dt.Columns.Add("size");
if (color.Length == size.Length && color.Length == count.Length)
{
List<string> listColor = new List<string>();
List<string> listSize = new List<string>();
foreach (string s in color)
if (!listColor.Contains(s))
listColor.Add(s);
foreach (string s in listColor)
dt.Columns.Add(s);
foreach (string s in size)
if (!listSize.Contains(s))
listSize.Add(s);
for (int i = 0; i < listSize.Count; i++)
{
DataRow dr = dt.NewRow();
dr[0] = listSize[i];
for (int j = 1; j < listColor.Count + 1; j++)
{
dr[j] = 0;
for (int k = 0; k < color.Length; k++)
{
if (listColor[j - 1] == color[k] && listSize[i] == size[k])
dr[j] = count[k];
}
}
dt.Rows.Add(dr);
}
}
GridView1.DataSource=dt;