c# - 在 Datalist 中显示 Mysql 数据库中的图像

标签 c# asp.net mysql

我将图像路径和图像名称保存在 myqsl 数据库中。现在我想在 ASP.NET 数据列表上显示数据库中的图像。我有这样的查询结果 enter image description here

我想显示带有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();
        }

但是显示是这样的 enter image description here

如何动态显示图像。基于查询。

最佳答案

编译后的 html 源代码是什么样的?显然图像路径一定是无效的。如果你检查 asp 所写的内容,这是否不能提供强有力的线索来说明问题出在哪里?

关于c# - 在 Datalist 中显示 Mysql 数据库中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15113362/

相关文章:

asp.net - 使用 json 仅序列化对象的一部分

mysql - 我是否需要 'User Account' 才能从 MySQL 数据库中检索数据?

MySQL错误子查询返回多于1行

c# - 使用 iTextSharp 生成 pdf 页脚

c# - 编辑 : Where and how should download temp files?

c# - 显示前的SqlDatasource进程记录

c# - 在 Umbraco v7.1.4 中获取所有用户

php - Openssl加密随 secret 钥&IV-存储在数据库中

c# - 我想将这个 foreach 循环转换为 LINQ 语句

c# - 如何在 VSTS 2010 中的单个项目中执行多个控制台 C# 程序