2015-08-08 27 views
-1

如何在asp.net頁面中顯示覆雜數據對象?實際上,下面的類是隻讀的,數據需要顯示在屏幕上,以便代理商可以告訴客戶他們需要付多少錢。我不想寫很多代碼來規範化並在頁面上顯示它。該數據通過Web服務方法調用返回。如何快速在asp.net頁面上顯示覆雜數據

public class FeeInfo { 

private string countryInfoTextField; 
public string CountryInfoTextField 
{ 
    get{return this.countryInfoTextField;} 
    set{this.countryInfoTextField= value;} 
} 
private stringfeeInfoTextField; 
public string FeeInfoTextField 
{ 
    get{return this.feeInfoTextField;} 
    set{this.feeInfoTextField= value;} 
} 
private string taxInfoTextField; 
public string TaxInfoTextField 
{ 
    get{return this.taxInfoTextField;} 
    set{this.taxInfoTextField = value;} 
} 

private string additionalInfoTextField; 
public string additionalInfoText 
{ 
    get{return this.additionalInfoTextField;} 
    set{this.additionalInfoTextField = value;} 
} 

private PromotionInfo[] promotionInfoField; //Class 

private SendAmountInfo sendAmountsField; //Class 

private EstimatedReceiveAmountInfo receiveAmountsField; //Class 

/// <remarks/> 
     [System.Xml.Serialization.XmlElementAttribute("promotionInfo")] 
     public PromotionInfo[] promotionInfo { 
      get { 
       return this.promotionInfoField; 
      } 
      set { 
       this.promotionInfoField = value; 
      } 
     } 

     /// <remarks/> 
     public SendAmountInfo sendAmounts { 
      get { 
       return this.sendAmountsField; 
      } 
      set { 
       this.sendAmountsField = value; 
      } 
     } 

     /// <remarks/> 
     public EstimatedReceiveAmountInfo receiveAmounts { 
      get { 
       return this.receiveAmountsField; 
      } 
      set { 
       this.receiveAmountsField = value; 
      } 
     } 
} 

我轉換到上述列表,並將其綁定到gridview的,但所有我看到的是4個字段,而不是最後3層複合物的性質。在屏幕上顯示這些數據的快捷方式是什麼?

+0

最後三個私人variables.They're不去類的外部被曝光。 –

+0

@AmitKumarGhosh這些變量也有3個公共屬性,就像其他變量一樣。對不起,我在這裏粘貼代碼時錯過了。只更新了代碼。 – Hitin

回答

-1

將一個toList方法添加到FeeInfo中。

public List<FeeInfo> toList(){ 
    var retList; 
    var props = this.GetType().GetProperties(); 
    foreach(var prop in props) { 
     if(prop.propertyType.IsArray) 
      for(int i=0;i<prop.length;i++) 
       retList.add(new GridView(prop.GetValue[i]); 
     else if(prop.propertyType.isClass) 
      retList.Add(new Gridview(prop.GetValue())); 
     else retList.Add(prop.GetValue()); 
    } 
    return retList; 
} 

不要有VS,以不幸ATM測試,以便有可能進行一些調整,使:)

+0

事實上,爲了進行這樣的編譯,需要進行一些調整。更不用說將類似Java的構造轉換爲通常可取的C#約定。 –

+0

我對這些可取的約定更感興趣。使它看起來更好。 VS社區正在安裝,因爲我會得到我的新工作筆記本電腦。 – Narcil

+0

@Narcil FeeInfo是通過Web服務方法返回的,如果我更改reference.cs文件,每次更新引用時,我所做的任何更改都將丟失。 – Hitin

相關問題