我将图像路径和图像名称保存在 myqsl 数据库中。现在我想在 asp.net 数据列表中显示数据库中的图像。我有这样的查询结果
我想用 pageName 显示图片。我在 datalst 上做了类似的事情。
<asp:DataList ID="dtlistImages" runat="server" RepeatColumns="3" RepeatDirection="Horizontal"
BorderColor="#336699" BorderStyle="Solid" BorderWidth="2px">
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text='<%# Eval("pageName") %>' Font-Bold="true"
Font-Size="10pt" ForeColor="#336699" Width="100%"/>
</br>
<asp:Image ID="imgnewspaper" runat="server" ImageUrl='<%# Eval("pageNumber") %>' />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Top" />
</asp:DataList>
代码背后:
public DataTable getData(string query)
{
MySqlConnection conn1 = new MySqlConnection(ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString);
conn1.Open();
MySqlCommand cmd = new MySqlCommand(query, conn1);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
protected void btnshow_onclick(object sender, EventArgs e)
{
string query = "select cap_newspaper_page.pageServer,cap_newspaper_page.pagePath, pageNumber,pageName,newspaper.newspaperName,newspaper_station.newspaperStationName"+
" FROM cap_newspaper_page Inner Join cap_newspaper ON cap_newspaper_page.capnewspaperID = cap_newspaper.capnewspaperID inner join newspaper on newspaper.newspaperID=cap_newspaper.newspaperID"+
" inner join newspaper_station on newspaper_station.newspaperStationID=cap_newspaper.newspaperStationID where cap_newspaper.newspaperID="+ddlNewspaper.SelectedValue+" and cap_newspaper.newspaperStationID="+ddlNewspaperStation.SelectedValue+" and cap_newspaper_page.publishDate='"+tbDate.Text+" 00:00:00'";
dtlistImages.DataSource = getData(query);
dtlistImages.DataBind();
}
但显示是这样的
我如何也可以动态显示图像。基于查询。