2013-02-14 95 views
3

我有一個場景,我必須顯示每個表字段的數據水平。水平顯示數據庫列數據

ID 1 2 3 4 5 

Name 'Ahmad' 'Umar' 'Nadeem' 'Raza' 'Saquib' 

City 'New York' 'Paris' 'London' 'New York' 'London' 

任何人都可以告訴我如何在ASP.NET C#中完成嗎?

+0

顯示你的代碼,請... – 2013-02-14 12:38:23

+5

你的問題已經回答了[這裏] [1] [1]:http://stackoverflow.com/questions/9758260/how-to-display-datagridview-perpendicular – Marco 2013-02-14 12:41:20

+0

如何獲取數據我的意思是使用數據集或列表? – Prashant16 2013-02-14 12:50:56

回答

1

類似的東西:

class Program 
{ 
    static void Main(string[] args) 
    { 
     HumanDto humanDto = new HumanDto(); 
     List<Human> humans = new List<Human>(); 
     humans.Add(new Human(){city = "London", id = 1}); 
     humans.Add(new Human() { city = "London2", id = 2 }); 
     humans.Add(new Human() { city = "London3", id = 3 }); 
     humans.Add(new Human() { city = "London4", id = 4 }); 

     humans.ForEach(e => humanDto.Add(e.city, e.id)); 
    } 
} 

public class Human 
{ 
    public Int32 id { get; set; } 
    public String city { get; set; } 
} 
public class HumanDto 
{ 
    public List<Int32> Ids { get; set; } 
    public List<String> Cities { get; set; } 
    public HumanDto() 
    { 
     Ids = new List<int>(); 
     Cities = new List<string>(); 
    } 

    public void Add(String city, Int32 Id) 
    { 
     Ids.Add(Id); 
     Cities.Add(city); 
    } 
}