什么数据库撒,oracle的话好像有个vm_ontact的函数,你百度哈子看看就明白了

解决方案 »

  1.   


      private void gvRender()
      {
        if (GridView1.Rows.Count <= 1)
        {
          return;
        }
        int icont = GridView1.Rows.Count;
        int i = 0;
        while (i < icont - 1)
        {
          TableCell oldtc = GridView1.Rows[i].Cells[1]; //cells[1]>>cells["belong"]
          for (int j = i + 1; j < GridView1.Rows.Count;j++)
          {
            i++;
            TableCell newtc = GridView1.Rows[j].Cells[1]; //cells[1]>>cells["belong"]
            if (newtc.Text == oldtc.Text)
            {
              newtc.Visible = false;          if (oldtc.RowSpan == 0)
              {
                oldtc.RowSpan = 1;
              }
              oldtc.RowSpan = oldtc.RowSpan + 1;
              oldtc.VerticalAlign = VerticalAlign.Middle;
            }
            else
            {
              break;
            }
          }
        }
      }belong列要先排序
      

  2.   


    sql2005的 
    后台画的表格为了动态显示合并
      

  3.   

    不是用的gridview 是后台画的表格。。不好意思 我没说清楚
      

  4.   

    group by belong select belong, string.joing(",", filiation)
    大致就这个思路,SQL或者linq都可以完成
      

  5.   

    SQL中的拼接STUFF
    http://www.cnblogs.com/yongheng178/archive/2012/06/27/2565631.html
      

  6.   


    还有其他数据我没截图截下来,因为就belong需要合并,我后台画表格输出html的 怎么循环?
      

  7.   

     你没看懂我的意思,我也没说清楚,不好意思,sql语句方面已经没法合并了,我现在把datatable填充到后台画的html表格里在后台直接合并,需要一个循环,不清楚怎么循环。。
      

  8.   

    不是用的gridview 是后台画的表格。。不好意思 我没说清楚    DataTable dt = myds.Tables[0];    int icont = dt.Rows.Count;
        int i = 0;
        while (i < icont - 1)
        {
          string oldtc = dt.Rows[i][3].ToString(); //Rows[i][3]>>Rows[i]["belong"]
          string strRowspan = string.Format("<td rowspan={0}>{1}</td>", "{0}", dt.Rows[i][3].ToString());
          int rowSpan = 0;
          string showMargeTable = string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>",
          dt.Rows[i][4].ToString(), dt.Rows[i][1].ToString(), dt.Rows[i][2].ToString(), dt.Rows[i][5].ToString());
          for (int j = i + 1; j < dt.Rows.Count; j++)
          {
            i++;
            string newtc = dt.Rows[j][3].ToString(); //Rows[i][3]>>Rows[i]["belong"]
            if (newtc == oldtc)
            {
              if (rowSpan == 0)
              {
                rowSpan = 1;
              }
              rowSpan ++;
              showMargeTable += string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>",
              dt.Rows[j][4].ToString(), dt.Rows[j][1].ToString(), dt.Rows[j][2].ToString(), dt.Rows[j][5].ToString());
            }
            else
            {
              showMargeTable= showMargeTable.Substring(0,showMargeTable.IndexOf("</td>")) + string.Format(strRowspan,rowSpan)
                + showMargeTable.Substring(showMargeTable.IndexOf("</td>"));
              showTable += showMargeTable;
              break;
            }
          }
        }
      

  9.   


      <table border="1">
      <%=showTable%>
      </table>public string showTable = "";
      

  10.   

    那就用linq吧
    右键添加对System.Data.DataSetExtensions.dll的引用using System.Linq;var result = from row in dataTable.AsEnumrable()
                         //where row.Field<int>("id")  <1000
                         group row by row.Field<string>("belong") into g
                         select new { Name = g.Key,  Value = string.Join(",", g.Field<string>("filiation ")) };这里的new {}是匿名类型,你可以根据需要自行修改
      

  11.   

    Value = string.Join(",", g.Select(r => r.Field<string>("filiation ")).ToArray())