还想问一个: 
      string aa="blue,red,blue,red,red" 
      string bb="12,12,13,13,14" 
      string cc="1,1,1,1,1" 
我的意识是颜色为blue的大小为12的有1件, 
          颜色为red的大小为12的有1件, 
          颜色为blue的大小为13的有1件, 
          颜色为red的大小为13的有1件, 
          颜色为red的大小为14的有1件。 然后我想把这些数据用 gridview表格绑定出来 
          如:          blue        red 
              12      1          1 
              13      1          1 
              14      1          0 
aa,bb,cc的长度不固定,但是,的个数都相同···· 
            不知道这样可不可实现 
希望大家帮忙~~~~~~~

解决方案 »

  1.   

    这个需要做一个行列互转将 aa bb cc 数组的数据遍历
    然后构建一个新的对象,如DataTable按照
            blue        red 
    12      1          1 
    13      1          1 
    14      1          0 的格式排列,具体的代码就不写了,办法总是有的
    可以考虑一下
      

  2.   

    这个只要把你的数据转换成   DataTable 就可以对  gridview 进绑定了  
      

  3.   


                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;