【问题标题】:asp.net, datalist image binding from folderasp.net,文件夹中的数据列表图像绑定
【发布时间】:2015-05-04 14:43:31
【问题描述】:

我正在尝试从文件夹中检索图像并将其显示在我的数据列表中,但不幸的是该图像未显示。

当我运行代码并检查元素时,它会显示正确的路径,但图像没有显示。

asp 代码

<asp:DataList ID="DataList1" runat="server" GridLines="Horizontal">
    <ItemTemplate>
        <table class="auto-style1">
            <tr>
                <td class="auto-style2" rowspan="6">
                    <img src= "<%# Eval(("Photo")) %>" />               
                </td>
    </ItemTemplate>
</asp:DataList>

C# 代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;



namespace CARSEZEE2015
{
    public partial class WebForm3: System.Web.UI.Page
    {
        SqlConnection con = new SqlConnection("Data Source=server name;Initial Catalog=catalogname;User ID=id;Password=password");
        protected void Page_Load(object sender, EventArgs e)
        {
            con.Open();
            SqlCommand cmd = con.CreateCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "Select * from DB";
            DataTable dt = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt);
            DataList1.DataSource = dt;
            DataList1.DataBind();
            con.Close();
        }
'

【问题讨论】:

  • 我格式化了你的代码,看起来你缺少很多你的 asp 代码...
  • 谢谢 JNYRanger,我刚刚粘贴了上面的主要数据列表 asp 代码,以避免混淆和混乱

标签: c# asp.net datalist


【解决方案1】:

您应该将图像路径和名称保存在数据库中:

例如“images/folder1/image1.jpg”

<img src= '<%# Bind("imgtp","~/{0}") %>' />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-11
    相关资源
    最近更新 更多