我该如何解决这个问题 [英] How Can I Solve This

查看:87
本文介绍了我该如何解决这个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<asp:ListView ID="ListView1" runat="server">


        <ItemTemplate>
            <li style="width: 150px; min-height: 200px;">
                <asp:Image ID="Image1" runat="server" ImageUrl='~/Images/logo/<%# Eval("logo") %>' />
                <br />
                <asp:Image ID="ImageUrl" runat="server" ImageUrl='~/Images/cpu/<%# Eval("pic") %>' />
                <br />
                <asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Eval("codename") %>' OnClick="LinkButton1_Click"></asp:LinkButton>
                <br />
                cost
                <asp:Label ID="ID" runat="server" Text='<%# Eval("cost") %>' />
                <br />
            </li>
        </ItemTemplate>
        <LayoutTemplate>
            <ul class="ItemContainer">
                <li  runat="server" id="itemPlaceholder" />
            </ul>

        </LayoutTemplate>

    </asp:ListView>



我的问题是asp:图片

我的图片在特定的文件夹中,我想要给它的静态地址和图像名称可以从数据库中读取

这段代码有什么问题,图片无法显示

请帮助


my problem is with asp:image
my images in specific folder and i want that give its address statically and image name can read from database
what is problem with this code,images cant shown
please help

推荐答案

您不能将数据绑定表达式与静态值组合在一起。



尝试:

You can't combine a data-binding expression with a static value like that.

Try either:
<asp:Image ID="Image1" runat="server" ImageUrl='<%# "~/Images/logo/" + Eval("logo") %>' />
<asp:Image ID="ImageUrl" runat="server" ImageUrl='<%# "~/Images/cpu/" + Eval("pic") %>' />





或:



or:

<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("logo", "~/Images/logo/{0}") %>' />
<asp:Image ID="ImageUrl" runat="server" ImageUrl='<%# Eval("pic", "~/Images/cpu/{0}") %>' />


这样的事情应该会有所帮助:

Something like this should help:
<asp:ListView id="ListView1" runat="server" onitemdatabound="ListView1_ItemDataBound">
...
...
<asp:Image id="Image1" runat="server" />
...
...
</asp:ListView>




protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e){
  Image img;
  if (e.Item.ItemType == ListViewItemType.DataItem){
    img=(Image)e.Item.FindControl("Image1");
    if(img!=null){
      System.Data.DataRowView rowView = e.Item.DataItem as System.Data.DataRowView;
      img.ImageUrl=string.concat("/Images/logo/",rowView["logo"].ToString());
    }
  }
}





希望它有所帮助。



hope it helps.


这篇关于我该如何解决这个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆