我在数据库表LoadFiled中有两个字段title和directory(图片路径),数据库显示如下:
 title           directory  xx             image1.jsp
  xx             image2.jsp
  xx             image3.jsp
我想把它绑定到asp.net的gridview中,由于title是一样的,所以怎样才能使他只显示一次title,在页面的table中显示形如:title            directory
 xx               image1
                  image2
                  image3 

解决方案 »

  1.   

    create table tb(title varchar(10) , directory varchar(10))
    insert into tb values('xx' ,           'image1.jsp') 
    insert into tb values('xx' ,           'image2.jsp') 
    insert into tb values('xx' ,           'image3.jsp') 
    goselect case when directory = (select min(directory) from tb where title = a.title) then title else '' end as title , directory
    from tb adrop table tb/*
    title      directory  
    ---------- ---------- 
    xx         image1.jsp
               image2.jsp
               image3.jsp(所影响的行数为 3 行)
    */
      

  2.   

    create table tb(title varchar(10) , directory varchar(20))
    insert into tb values('xx' ,           'image1.jsp') 
    insert into tb values('xx' ,           'image2.jsp') 
    insert into tb values('xx' ,           'image3.jsp') 
    go--方法一
    select case when directory = (select min(directory) from tb where title = a.title) then title else '' end as title , directory from tb a--方法二
    select case when directory = (select top 1 directory from tb where title = a.title ) then title else '' end as title , directory from tb adrop table tb/*
    title      directory  
    ---------- ---------- 
    xx         image1.jsp
               image2.jsp
               image3.jsp(所影响的行数为 3 行)
    */