asp.Net Gridview显示数据类型而不是值

asp.Net Gridview显示数据类型而不是值,asp.net,gridview,dynamics-crm-2011,Asp.net,Gridview,Dynamics Crm 2011,我遇到了一个小问题,找不到解决办法 当gridview绑定时,所有价格将显示为Microsoft.Xrm.Sdk.Money,而不是其值 有人知道为什么会发生这种情况以及如何改变它吗 以下是我的Gridview: <asp:GridView ID="ProductList" runat="server" AutoGenerateColumns="false" OnRowDataBound="ProductList_OnRow

我遇到了一个小问题,找不到解决办法

当gridview绑定时,所有价格将显示为
Microsoft.Xrm.Sdk.Money
,而不是其值

有人知道为什么会发生这种情况以及如何改变它吗

以下是我的Gridview:

<asp:GridView ID="ProductList" 
          runat="server" 
          AutoGenerateColumns="false" 
          OnRowDataBound="ProductList_OnRowDataBound">
  <Columns>
    <asp:BoundField 
        HeaderText="Productno." 
        DataField="ProductNumber"/>

    <asp:BoundField 
        HeaderText="Product" 
        DataField="Name" />

    <asp:BoundField 
        HeaderText="Price/Unit" 
        DataField="Price" />
  </Columns>
</asp:GridView>
目前看起来是这样的:

PNo.     Name        Price 
1        Prod 1      Microsoft.Xrm.Sdk.Money
2        Prod 2      Microsoft.Xrm.Sdk.Money
3        Prod 3      Microsoft.Xrm.Sdk.Money
....
在xrm.cs上(为与CRM的早期绑定生成的文件)

其内容如下:

[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("price")]
public System.Nullable<decimal> Price
{
    get
    {
        return this.GetAttributeValue<System.Nullable<decimal>>("price");
    }
    set
    {
        this.SetAttributeValue<Microsoft.Xrm.Sdk.Money>("Price", "price", value);       
    }
}
[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute(“价格”)]
公共系统。可取消价格
{
得到
{
返回此.GetAttributeValue(“价格”);
}
设置
{
此.SetAttributeValue(“价格”、“价格”、价值);
}
}

您可以使用
模板字段
来显示
价格
字段的
属性(包含十进制值)。我在您的示例中添加了另一个专栏


我没有找到有效的解决方案

我所做的一切都是有效的:

Products = (from ppl in priceCatalog.price_level_product_price_levels
        join prod in ServiceContext.ProductSet.ToList()
             on ppl.ProductId.Id equals prod.ProductId
        select new ProductClass()
        {
            ProductId = prod.ProductId,
            ProductNumber = prod.ProductNumber,
            Name = prod.Name,
            Price = prod.Price,
            //Price = ppl.Amount.Value,
            PriceLevelId = ppl.PriceLevelId,
            SubjectId = prod.SubjectId,
            DefaultUoMId = ppl.UoMId
        }).ToList();
我创建了一个新类,在这一点上我使用了它。现在它可以工作了:

Products = (from ppl in priceCatalog.price_level_product_price_levels
        join prod in ServiceContext.ProductSet.ToList()
             on ppl.ProductId.Id equals prod.ProductId
        select new ProductClass()
        {
            ProductId = prod.ProductId,
            ProductNumber = prod.ProductNumber,
            Name = prod.Name,
            Price = prod.Price,
            //Price = ppl.Amount.Value,
            PriceLevelId = ppl.PriceLevelId,
            SubjectId = prod.SubjectId,
            DefaultUoMId = ppl.UoMId
        }).ToList();

noew我正在获取数据绑定:'System.String'不包含名为'Value'的属性。如果
Price
Microsoft.Xrm.Sdk.Money
对象,
Value
属性将正确绑定,则在分配属性时可能出现问题。尝试以这种方式仅绑定价格
绑定(“价格”)
并检查输出是否为货币类型,请参见我的编辑。I stll获取类型而不是其值:-(您从xrm.cs获取的代码不正确或不属于Product.Price,正确的代码是这样生成的(请复制并粘贴到VS中):[Microsoft.xrm.Sdk.attributeLogicNameAttribute(“Price”)]public Microsoft.xrm.Sdk.Money Price{get{返回此.GetAttributeValue(“价格”);}set{this.onPropertyChange(“价格”);this.SetAttributeValue(“价格”,值);this.OnPropertyChanged(“价格”);}}不幸的是,这对我没有帮助,但我发现我并没有创建一个新产品(选择),然后它工作正常。有更好的方法让产品与价格表相关吗?