0

我将图像路径和图像名称保存在 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();
        }

但显示是这样的 在此处输入图像描述

我如何也可以动态显示图像。基于查询。

4

3 回答 3

1

what does the source code for the compiled html look like? clearly the image paths must be invalid. if you check what the asp has written does this not give a strong clue as to what is wrong?

于 2013-02-27T13:40:07.653 回答
1

You only have pageNumber and not pagePath in your Eval

于 2013-02-27T13:41:11.677 回答
0
<asp:Image ID="imgnewspaper" runat="server" ImageUrl='<%#  Eval("pagePath") %>' />

或者
您在本地缺少项目文件夹中的图像printImages,如果您在本地运行它,并且如果您在实时服务器上运行它,那么还要检查该文件夹中的图像。

建议我通过以下方式实现了同样的目标:

    <asp:ListView ID="ImagesList" runat="server" DataKeyNames="ID" GroupItemCount="4"  OnPagePropertiesChanging="ImagesList_PagePropertiesChanging">
        <EmptyDataTemplate>
            No Images found.
         </EmptyDataTemplate>
          <ItemTemplate>
               <asp:ImageButton ID="MyPicture" runat="server" OnClick="MyPicture_Click" CommandArgument='<%# Eval("ID") %>'  AlternateText='<%# Eval("Name") %>' ImageUrl='<%# Eval("ImagePath") %>' Autopostback="true"Width="155" Height="80" />
  </ItemTemplate>
</asp:ListView>
于 2013-02-27T14:11:55.023 回答