Click here to Skip to main content
15,911,785 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
ASP.NET
<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>

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
Posted
Comments
hypermellow 16-Jul-14 10:06am    
When you run this, then view the page source in your browser, what value does the image have for it's source attribute?
m-e-h-d-h-i 16-Jul-14 10:11am    
http://localhost:1963/ars-co.ir/Images/logo/%3C%25#%20Eval(%22logo%22)%20%25%3E

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

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


or:
ASP.NET
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("logo", "~/Images/logo/{0}") %>' />
<asp:Image ID="ImageUrl" runat="server" ImageUrl='<%# Eval("pic", "~/Images/cpu/{0}") %>' />
 
Share this answer
 
Comments
m-e-h-d-h-i 16-Jul-14 10:54am    
thanks for help
Something like this should help:
ASP.NET
<asp:ListView id="ListView1" runat="server" onitemdatabound="ListView1_ItemDataBound">
...
...
<asp:Image id="Image1" runat="server" />
...
...
</asp:ListView>

C#
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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900