<asp:Repeater ID="rptProducts1" runat="server">
<ItemTemplate>
<div class="product_header">
<asp:Label ID="prodLabels" runat="server" >
<p><h4><%#Eval("Name") %></h4></p>
</asp:Label>
</div>
<div class="left-col">
<div class="img_product">
<asp:Image ID="imgProduct" runat="server" ImageUrl='<%# Eval("Picture") %>' Width="200px" Height="200px"/>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
Code Behind:
List<ProductModel> _prodObj = new List<ProductModel>();
_prodObj = response.Content.ReadAsAsync<List<ProductModel>>().Result;
_prodObj.Where(x => x.PictureId != 0).Select(v => v.Picture = "data:image/png;base64," + Convert.ToBase64String(v.PictureBinary));
var _prodname = _prodObj.Where(x=>x.Id!=0).Select(i => i.Name=""+i.Name);
try
{
rptProducts1.DataSource = _prodname;
rptProducts1.DataBind();
}
catch (Exception ex)
{
throw;
}
從數據庫中獲取數據時發生問題。想要顯示產品的名稱和圖像。在獲取記錄時'System.String'不包含屬性錯誤。'System.String'不包含屬性
在此先感謝。
感謝先生,但是不是如何根據其單品 –
所以,你只是想顯示一個產品的ID顯示名字?那麼中繼器不是做這件事的方法,因爲這個控件是用來和一系列的項目一起使用的。我只需在其中放置一個asp:標籤,然後更改其Text屬性以設置名稱。我用一個例子更新了我的答案。這有幫助嗎? –