おそらく本当に基本的なことだと思うので、この質問で申し訳ありませんが、私はそれで多くの問題を抱えているようです.
私がやろうとしているのは、データベースに保存した画像を取得し、それを ListView にバインドすることです。
データベースには画像自体がありません。画像の名前があるので、PathWay を使用して取得しようとしています。
私は ASP.NET Web フォーム Web サイトを使用しています ここに ListView を示します。
<asp:ListView runat="server" ID="lvBrands" OnItemDataBound="lvBrands_ItemDataBound">
<LayoutTemplate>
<ul class="grid portfolio isotope no-transition portfolio-hex portfolio-shadows row demo-3 os-animation" data-os-animation="fadeInUp">
<li runat="server" id="itemPlaceholder"></li>
</ul>
</LayoutTemplate>
<ItemTemplate>
<li class="portfolio-item col-md-3 col-sm-3 style fashion grid cs-style-3">
<figure class="portfolio-figure">
<img src="images/products/test.jpg" alt="work-01" />
<figcaption>
<h4 class="title purpleColored" color="#58387B"><%# Eval("name") %></h4>
<span><%# Eval("keyword") %></span> <a class="text-right" href="javascript:;"><i class="fa fa-angle-right"></i></a>
</figcaption>
</figure>
</li>
</ItemTemplate>
</asp:ListView>
代わりに<img src=... />
、適切なブランドに適切な画像を表示できるように、画像経路を添付する必要があります。
Brands は sql で作成したテーブルです。基本的に、Brands と Pictures の関係は 1 対多です (1 つの Brand に多数の画像を含めることができます)。
これまでに検索した内容では、 を使用しOnItemDataBound
てデータベースから画像を取得する方がよいことがわかりました。さらに助けていただければ幸いです。
さらにヘルプが必要な場合は、C# コードを次に示します。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DisplayBrands();
}
}
protected void DisplayBrands()
{
using (Entities db = new Entities())
{
List<Brand> brand = db.Brands.ToList();
lvBrands.DataSource = brand.OrderByDescending(b => b.date_created);
lvBrands.DataBind();
}
}
}
関数 lvBrands_ItemDataBound を指定する必要があることはわかっていますが、正直なところ、何を追加すればよいかわかりません。
どんな助けでも素晴らしいでしょう、ありがとう!