我需要将Prod_Picture显示在图片中,而不是路径文本。我无法在GridView中设置属性,因为我将此代码绑定到GridView,并且没有在那里创建任何列。
protected void Page_Load(object sender, EventArgs e)
{
var item = from c in db.Products
join o in db.ProductCategories
on c.ProdC_ID equals o.ProdC_ID
select new
{
ProductID = c.Prod_ID,
ProductName = c.Prod_Name,
Price = c.Prod_Price,
Amount = c.Prod_Amount,
Picture = c.Prod_Picture,
ProductDetail = c.Prod_Detail,
ProductCategory = o.ProdC_Name
};
GridView1.DataSource = item;
GridView1.DataBind();
}
GridView的源代码:
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
请帮助!!
答案 0 :(得分:2)
您可以参考以下主题:
Displaying Images from a Database in a GridView
对gridview执行以下操作:
答案 1 :(得分:1)
我认为您将图片Url存储为Prod_Picture。 在那种情况下
<asp:BoundField DataField="Prod_Name" HeaderText="Prod_Name" />
<asp:BoundField DataField="Prod_Price" HeaderText="Prod_Price" />
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:Image ID="Image1" ImageUrl='<%# (string) FormatImageUrl( (string) Eval("Prod_Picture")) %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<RowStyle BackColor="White" ForeColor="#330099" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
</asp:GridView>
这将起作用