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

时间:2015-08-08 12:44:40

标签: c# asp.net web-services data-binding

如何在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个复杂属性。什么可以快速,快捷地在屏幕上显示这些数据?

1 个答案:

答案 0 :(得分:-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所以可能会进行一些调整:)