【发布时间】:2017-07-22 03:44:09
【问题描述】:
我在尝试从数据库中显示我的 DataList 中的图像并有权访问我从中提取图像的数据库时遇到问题。但是当我运行WebForm 时,图像没有出现,我的代码有什么问题?
<asp:DataList ID="DataList1" runat="server" DataKeyField="dishID" DataSourceID="SqlDataSource1" BorderStyle="Solid" GridLines="Both" RepeatColumns="4" RepeatDirection="Horizontal" Width="1259px" >
<ItemTemplate>
<table class="auto-style1">
<tr><td>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# "FoodPictures/" + Eval("dishImage") %>' />
这就是我从数据库中检索的方式:
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(_connStr);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from Dish";
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
conn.Close();
DataList1.DataSource = dt;
DataList1.DataBind();
conn.Close();
}
【问题讨论】:
-
图片在数据库中存储了什么?图片路径还是图片数据?你是如何从数据库中检索的?可以分享一下后端代码吗?
标签: c# asp.net image webforms datalist