如何在asp.net页面上快速显示复杂的数据

本文关键字:显示 复杂 数据 asp net | 更新日期: 2023-09-27 18:06:54

如何在asp.net页面中显示复杂的数据对象?实际上下面的类是只读的,数据需要显示在屏幕上,这样座席就可以告诉客户他们需要支付多少钱。我不想写很多代码来规范它并在页面上显示它。该数据由web服务方法调用返回。

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个复杂的属性。在屏幕上快速显示这些数据的方法是什么?

如何在asp.net页面上快速显示复杂的数据

为FeeInfo添加一个toList方法。

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不幸的是,所以可能有一些调整要做:)